局限三有问题。"hello" instanceof String.class 也没这种用法啊,应该是"hello" instanceof String
Topic source我发现jdk14下面 可以写p instanceofPair<Integer>, 而jdk8只能写p instanceofPair
Pair<Integer> p = new Pair<>(123, 456);
if (p instanceof Pair<Integer>) {
System.out.println(true);
}
你都知道了p是Pair<Integer>后面再判断有什么意义?
Pair<Integer> p = ...
if (p instanceof Pair<Integer>) {
...
}
如果你不知道p的类型又编译不过:
Object p = ...;
if (p instanceof Pair<String>) { // compile error
}
所以instanceof根本无法判断带泛型的类型
- 1
kylechli