return-type

How do you apply a .net attribute to a return type

How do I apply the MarshalAsAttribute to the return type of the code below? public ISomething Foo() { return new MyFoo(); } ...

Return type polymorphism in C-like languages

Why don't we see C-like languages that allow for callables with polymorphism in the return type? I could see how the additional type inference would be a hurdle, but we have plenty of languages with full-fledged type inference systems (that work for varying levels of "work"). Edit: By return type polymorphism I mean overloading the func...

Datatype of SUM result in MySQL

I'm having a bit of a problem with converting the result of a MySQL query to a Java class when using SUM. When performing a simple SUM in MySQL SELECT SUM(price) FROM cakes WHERE ingredient = 'chocolate'; with price being an integer, it appears that the SUM sometimes returns a string and sometimes an integer, depending on the version...

How Can I Avoid Using Exceptions for Flow Control?

I have been assigned a project to develop a set of classes that act as an interface to a storage system. A requirement is that the class support a get method with the following signature: public CustomObject get(String key, Date ifModifiedSince) Basically the method is supposed to return the CustomObject associated with the key if an...

why do functions dont have parameterized return types, as it has parameterized input?

This always forces us to return a single parameter in case I need to return multiple, say a List and a String. This restriction is not there in function arguments. ...

How to search for all methods in a project that return implementation of Collection interface?

I've been reading Josh Bloch's 'Effective Java 2nd Edition'. Item 43 states 'Return empty arrays or collections, not nulls'. My question is how can I search for all methods in a project that return an implementation of java.util.Collection interface? IDE that is used is Eclipse, but any way of finding the right result is acceptable, e.g....

Should I return an array or a collection from a function?

What's the preferred container type when returning multiple objects of the same type from a function? Is it against good practice to return a simple array (like MyType[]), or should you wrap it in some generic container (like ICollection<MyType>)? Thanks! ...

Is it good to have all the setter functions return a reference to the object in c++?

Is it good to have all the setter functions return a reference to the object in c++? ...

String or StringBuilder return values?

If I am building a string using a StringBuilder object in a method, would it make sense to: Return the StringBuilder object, and let the calling code call ToString()? return sb; OR Return the string by calling ToString() myself. return sb.ToString(); I guess it make a difference if we're returning small, or large strings. What wo...

Why doesn't this return type work? (C++)

When I try to use my iterator class template<class T> class list { public: class iterator; }; template<class T> class list<T>::iterator { //stuff }; as a return type in an operator overloading, template<class T> class list<T>::iterator { public: iterator& operator++(); protected: list* lstptr; }; template<class T> iterator& list<T>...

How to get an 'array of strings' as a function's return type?

String[] decode(String message) Above is an example. I need to get 2 strings s1 and s2 as the return values for the decode function. How should I proceed? ...

What is the great wisdom in defining your own object if I can't do this?

This is for Excel and VBA. Assume that BondClass has been properly defined in a Class Module. I get a #VALUE! when I type "=GetBondPrincipal()" into an Excel cell. Have I done something syntactically wrong or is this just not possible in Excel/VBA? I ask because what I really want to do is this: http://stackoverflow.com/questions/1354046...

How to return dynamic return types in methods? C#

I am having a problem with the return type of a method. The method returns a linq object which at present returns type tblAppointment. This method is shown below: public tblAppointment GetAppointment(int id) { var singleAppointment = (from a in dc.tblAppointments where a.appID == ...

C#, dynamic return type

Hi all, What I need is a method that can return a type (no object, cause no casting allowed) following a condition. Here is an example: ??? right (string fullStr, int endPosition) { string tmpStr = ""; tmpStr = fullStr.Substring(endPosition); if(tmpStr.Length == 1) return tmpStr[0]; //return a char!! else return tmpStr; //r...

Changing return type when overidding a function in the subclass in PHP?

Is this bad? Or this is very common in PHP framework? For example, in the parent class, there is a save() function which returns the number of rows affected in the database. Then in the child class, I override this function to do some pre-validation, and also would like to simply return a success/failed boolean value. ...

Why should functions always return the same type?

I read somewhere that functions should always return only one type so the following code is considered as bad code: def x(foo): if 'bar' in foo: return (foo, 'bar') return None I guess the better solution would be def x(foo): if 'bar' in foo: return (foo, 'bar') return () Wouldn't it be cheaper memory wise to return a None ...

Should methods with return type void use a return statement?

I know that there are times when using return; can serve a useful purpose in Java, such as in guarding: public void foo(Bar bar) { if(bar == null) return; // bar is not null, go ahead and do stuff with it } But what about just reaching the end of a method with return type void? For example, public void printMenu() {...

Is there a standard "never returns" attribute for C# functions ?

I have one method that looks like this: void throwException(string msg) { throw new MyException(msg); } Now if I write int foo(int x, y) { if (y == 0) throwException("Doh!"); else return x/y; } the compiler will complain about foo that "not all paths return a value". Is there an attribute I can add to t...

Java generics extending return type of methods

Take a look at these three classes. Minatchi allows itself to be extended so that its methods' returning type could be extended as well. To illustrate, I used a static method. public class Minatchi<T extends Minatchi<?>>{ static public <T extends Minatchi<?>> List<T> listAll(){ return (List<T>) query(); } } And ...

Returning from a multimap search with equal_range without being error-prone

I'm about to refactor some duplicated code. Two functions both search in a multimap using equal_range(). In a for loop after the call to equal_range() there is a for loop that sets an iterator to equalRange.first with the condition it != equalRange.second. If the correct value is found, the two functions differ. What I would like to do...