How to check instance of a generic class?
Hi everyone,
I tried to check an instance of Object type with a JFS' class TreeMap<T1, T2>, but I don't know how. Could anyone help me out?
Code:
import java.util.TreeMap;
public class TreeOrHashMap
{
private Object instance;
public void doSomething()
{
ins = new TreeMap<Integer, Integer>();
if( ins instanceof TreeMap<Integer, Integer> )
TreeMap<Integer, Integer> m = ( TreeMap<Integer, Integer> )( ins );
m.put( 1, 1 );
}
}
Errors:
Quote:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
ins cannot be resolved to a variable
ins cannot be resolved to a variable
Syntax error on token ")", { expected after this token
ins cannot be resolved to a variable
Syntax error, insert "}" to complete Statement
at TreeOrHashMap.doSomething(TreeOrHashMap.java:9)
at Program.main(Program.java:8)