Tagged Questions
4
votes
4answers
76 views
generic type and assignment problems
I know that , every generic type variable replaced to upper bound that has been determined from the generic definition in the start of method "type-parameter section".
this is from Deitel book
...
1
vote
2answers
36 views
Reference type dependency - declare Map.Entry to be dependent on generic types declared for TreeMap
let's imagine this scenario - I would like to use TreeMap in java. It's part of the Colletions framework and the only implementation of the SortedMap interface.
public class MyDictionary extends ...
1
vote
1answer
44 views
maven refuses to compile generic class due to bounds, even after casting class
Here is a simplified version of the code I'm using to hold a generic list of children to a parent. Forgive me for having to rewrite this by hand instead of copy-past, There is no way to copy from ...
6
votes
1answer
71 views
Java generics, get Class<T> of generic parameter
I have an abstract class:
public abstract class RootProcessor<T> {
Class<T> clazz;
}
I need to fill ClassT clazz; with the children of RootProcessor - every child has its own T
I ...
4
votes
7answers
99 views
Return reversed generic list-type in Java
I'm doing some exercises on generic programming; is there a way to take a class that implements List and return a reversed version of that same class? It seems this should be feasible as this, at ...
0
votes
2answers
28 views
Java Generic Parameter Bound In Instantiation
Having a major brain fart right now.
I have this:
public static final Map<WorkType, Class> handler;
Then
handler = new TreeMap<WorkType, Class>() {{
put(WorkType.SUBMIT, ...
0
votes
2answers
44 views
How to serialize Java generics with SimpleJson
I want to use a generic model to broadcast different data over websocket from server to client. Unfortunatley I always get an error while wanting to serialize the following class structure:
Class to ...
2
votes
2answers
52 views
Generics: Cannot convert from Collections.emptyList() to List<String>
Why
public List<String> getList(){
if (isMyListOKReady())
return myList;
return Collections.emptyList();
}
compiles well, but for
public List<String> getList(){
...
6
votes
8answers
179 views
Java generics, list of lists
This thing has me stumped. I have a class as follows:
public class SpecialList implements List<MyType> {
// overriden methods
}
Now I have the following method contract to respect in a ...
-1
votes
1answer
33 views
Reflect method get type of generics when the generics is String [closed]
This is mycode. I don't know when I want to get the type of generics used reflect method. I know the generics just run in Compilation time. when I used the Integer or other type, it'll Correctly.
...
0
votes
1answer
65 views
Yet another Java generics “incompatible types” compilation error
I was writing some code and came across a incompatible types compilation error.
This is what I have:
public interface Expression<T> {
int getArity();
T evaluate();
}
public abstract ...
-1
votes
0answers
31 views
Nested collections of arbitrary depth, generics
There are other, easier, ways of creating k-ary trees but I am trying to see if it is possible to create trees with generics where the root has direct access to all its descendants by way of nested ...
4
votes
2answers
142 views
Defining abstract math with java
I am trying to define some basic mathematical concepts in java, but keep getting stuck with generics errors. Consider the example below.
In this example, I try to define the zero mapping (f(x) = 0 for ...
2
votes
1answer
61 views
Override generic methods through interfaces
I have some contents, generated by this interface:
public interface Content {
void addListener(ContentListener<?> listener);
}
Like GenericContent:
public interface GenericContent ...
1
vote
2answers
39 views
Eliminate Intermediate Step in Cast
I am using import org.springframework.data.repository.support.Repositories to get an instance of a Spring Data Repository within a Quartz Job.
The Repositories class has a ...