Generics trouble

[b][red]This message was edited by fladimir at 2006-10-8 15:15:1[/red][/b][hr]
[b][red]This message was edited by fladimir at 2006-10-8 15:5:14[/red][/b][hr]
I'm trying to do the following:

[code]
public T foo(T value) {
// Error: Cannot cast Class to Class
Class clazz = value.getClass();
}
[/code]

Even if they're in fact the same! A cast "works", but it generates a warning about type safety.

I can't find a way to do that... or something like this:

[code]
public void foo(List values) {
Class clazz = ?; // what can I do here? T.class doesn't obviously work...
}
[/code]

Thanks in advance, Java gurus!

EDIT: An another one:

[code]
class Super {
public abstract void processChildren(
String childName, List children, Class childClass)
}

class Child extends Super {
public void processChildren(
String childName, List children, Class childClass) {
//...
}
}
[/code]

[italic]Name clash: The method processChildren(String, List, Class) of type Child has the same erasure as processChildren(String, List, Class) of type Super but does not override it [/italic]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories