SeanChang 最近的时间轴更新


V2EX 第 7483 号会员,加入于 2011-03-30 20:47:30 +08:00
27 S 80 B
SeanChang 最近回复了
125 天前
回复了 jawe001 创建的主题 Java 求 Java 大佬帮忙分析下这个程序
The incomparable types error is telling you that it doesn't make sense to compare two things that cannot possibly be equal.

For example, there's no point in Integer.valueOf(0) == "", because they're not the same types; nor is one a supertype of the other. It will always be false.

The compiler will prevent the a == b if both are class types (as opposed to interfaces), and both a = b and b = a would be disallowed.

So, you are being told that a Class<? extends T[]> cannot be equal to a Class<Object[]>, because you can't assign a reference of one type to a variable of the other type.

By casting one of the references to Object, the compiler no longer knows (/thinks) that the types are definitely not related - because Object is a supertype of everything, so "nor is one a supertype of the other" is no longer true - so the compiler allows the check.

One thing that is redundant in that method is U. There's no need for it, just use Object[] in the parameter type instead.
关于   ·   帮助文档   ·   博客   ·   nftychat   ·   API   ·   FAQ   ·   我们的愿景   ·   广告投放   ·   实用小工具   ·   1139 人在线   最高记录 5556   ·     Select Language
World is powered by solitude
VERSION: · 20ms · UTC 23:01 · PVG 07:01 · LAX 16:01 · JFK 19:01
Developed with CodeLauncher
♥ Do have faith in what you're doing.