What is the difference between these 2 methods

What is the difference between these 2 methods which work similar. Can any one explain me the exact difference? **Accepts the list with all Number Type** public static double sum(List<? extends Number> list) { double sum = 0; for(Numbe...
more »

2017-08-17 18:08 (1) Answers

Generic getter that returns Object of Child Class

Let's assume I have 3 classes: Car, Convertible and Garage. Car is an abstract class that Convertible inherits from: Convertible has one specific method called unfoldRoof(). Garage contains one Car with the following getCar() method: public Car g...
more »

2017-08-17 16:08 (4) Answers

Swift 4 collection of Codable objects

I have a Codable class with a variable that holds a dictionary with String keys and values that may be Strings, Ints or custom structs conforming to Codable. My question is: How do I define a dictionary with values that are Codable? I hoped it woul...
more »

2017-08-17 14:08 (2) Answers

How to create a generic list of generics?

Please see my below code, I am trying to create a list of an interface which uses generics, but I need the generic version. So that you're aware, the generic type may differ for each entry in the list, it won't just be a list of IFoo with the same ge...
more »

2017-08-17 13:08 (1) Answers

Scala generic implicit val

I have a lot of implicit val for enum to json transformations in my program like that: implicit val format = new Format[AuthRoleIndividual] { def reads(json: JsValue) = JsSuccess(AuthRoleIndividual.withName(json.as[String])) def writes(myEnu...
more »

2017-08-17 12:08 (1) Answers

Explain Java Generic Modifying Standard Type

This signature: public static <E extends Enum<E>> String getEnumString(Class<E> clazz, String s) is not found anywhere I could see in the Oracle Java documentation for Generics. It appears to use a generic typecast of the returne...
more »

2017-08-16 19:08 (1) Answers

Class Design w/ Generics

I've recently gotten more involved in class design. I am having trouble coming up with a good class design for the following scenario. I have a generic, abstract base class which, for simplicity's sake, looks like this: public abstract class Elemen...
more »

2017-08-16 14:08 (1) Answers

Possible to Make a Generic Enum UIPickerView

Is it possible to write a generic UIPickerView subclass where you could pass in an arbitrary enum type and have it fill the picker view with all the cases of said enumeration? Note: This needs to be done generically for an arbitrarily passed in enum...
more »

2017-08-15 22:08 (2) Answers

Generics Call method on Enum

I have this exemple code: class Enum Test { TEST("test") { @Override public void someThing(Param one) { // ... } } public abstract void someThing(Param one); } How I can call the method "someThing" u...
more »

2017-08-15 22:08 (0) Answers

Merging two Generic collections

What I am trying to achieve in perspective - is implement generic Merge Sort function. So I need to compare and merge each element of the collection with the next one, again and again, until there will be only one collection left. However, this is n...
more »

2017-08-15 19:08 (0) Answers