Skip to content
Advertisement

Tag: generics

What’s the meaning of this line of code? And how can I create an object of this class?

I was trying to construct an object of the MTree class (https://github.com/Waikato/moa/blob/master/moa/src/main/java/moa/clusterers/outliers/utils/mtree/MTree.java) The constructor of MTree looks like this: The DistanceFunction here is an interface, the code of it is: And it’s implementation is: And my first question is what’s the meaning of return new DistanceFunction<Data>() in the method public static <Data> DistanceFunction<Data> cached(final DistanceFunction<Data> distanceFunction) [the method is in

Using Generics for return type parameter Java

I am trying to create a method that will return a generic type parameter. I have a class VehicleOrder that extends the abstract class Order. In class Order, I created an abstract method receiveHiredObject. This method will not receive any parameter and will return a generic. I implemented this method in the class VehicleOrder and I set it up to

ClassCastException on raw functional interface lambda invocation

Consider this example: The last line will give java.lang.ClassCastException: class java.lang. Object cannot be cast to class java.lang.String. This is not a surprise for me, as Function is declared to accept String. I know that raw types can give ClassCastException, but all examples I saw are about ClassCastException on unchecked call return object not about method arguments: I can find

Generics code not working when i try to return concrete object

The goal i am trying to achieve, is to have different FileLoaders like CSVFileLoader, ExcelFileLoader that can load up any object of type T, as long as it know how to convert using ‘C’ and create the object of type T. Hope this makes sense. I am trying to use generics to create a generic FileLoader that will take a

Advertisement