Nested generic types in static method

I was looking for a solution to this problem, I need to build the method so that it returns someObject, I was thinking about building something like this: public static <T, K&…

Java Generics – argument type and casting

I have a generics problem I am trying to resolve. I’m doing some manual casting and it feels like I’m doing something wrong. I’m a bit new to using generics, so it’s very much possible I am misusing …

How to capture and propagate a wildcard type argument?

I have a couple of classes having identical methods, except with respect to certain parameter types: interface ICls { void doSomething(String key, T value); Map …

How to use one type in method?

I have two forms, one form to create user and one to update user.These forms are similiar and I want to use one type in my method,I wouldn’t like to create two methods one to create user from …

Compare elements of two arrays of Object

I am trying to build a generic merge method, part of a mergeSort algorithm but I am stuck on how to deal with the comparison. This is my code so far: public static Object[] merge(Object[] left, Object[…

Is it possible to make a generic functional interface with optional parameter(s)?

I’m trying to create a functional interface in Java with a single method (of course) that can take any type of parameter(s) and return any data type (i.e. a generic method). This is what I have so far:…

Java enum with generic attributes

I have been trying to create enum that contains generic attribute, for example: public enum SomeEnum { SOME_VALUE_1(SomeValue1.class), SOME_VALUE_2(SomeValue2.class); private final Class&…

Does it matter if function returns T or object if T can not be inferred from context?

I found the following source code in gson: public T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException { JsonReader jsonReader = newJsonReader(json); T …

Casting Issue for Generic Array of Node Objects

I am having problem with java generic array creation where I needed to make an array of type Node. So, I did this for declaration: private Node [] nodes; and later for initialization, nodes = …

Java Generics – quick question on Greater Than Method with Objects

I have an assignment in my Java class, we are learning Generics, I have looked in my notes, my lessons, and even on the internet and I still cant figure out what this last assignment question is …