试图用一个例子来解释Java的泛型不能模拟鸭子类型:
类Caller { final T callee;Caller(T callee) { this.callee = callee;} publicvoid (){ callee.call();/编译器错误:无法找到符号调用}类Foo {公共空调用(){ System.out.print("Foo");}} class Bar { System.out.print与C++的模板不同,Ca
我有一个可缓存的接口 K denotes the type of the key of a cacheable objectpublic interface Cacheable<interface Cache<K, T extends Cacheable>{ T put(T cacheable);虽然这是可行的,但我希望这样做更好,因为上面的内容并不表示T和K之间的关系,换句话说,T.getKey应该返