是桥接方法吗?
Is it a bridge method?
为什么可以用两个签名相同的方法编译 class?
"foo" 方法只有 return 种不同的类型。
但是 return 类型不是 java.
方法签名的一部分
在这种情况下,java 编译器会创建桥接方法吗?
如果是 - 真实代码会是什么样子?
foo 方法有以下警告:
Method foo(GenClass) has the same erasure foo(GenClass) as
another method in type test
如果取消注释栏方法,栏方法将出现以下错误:
Method bar(GenClass) has the same erasure bar(GenClass) as
another method in type test
class GenClass<T> {
}
public class test {
public static void main(String[] args) {
}
public static Integer foo(GenClass<Integer> criteria) {
System.out.println("Integer");
return null;
}
public static String foo(GenClass<String> criteria) {
System.out.println("String");
return null;
}
/*public static void bar(GenClass<Integer> criteria) {
System.out.println("Integer");
}
public static void bar(GenClass<String> criteria) {
System.out.println("String");
}*/
}
D:\tools\java\jdk1.6.0_37_32\bin>java -版本
java 版本“1.6.0_38”
Java(TM) SE 运行时环境(build 1.6.0_38-b05)
Java HotSpot(TM) 64 位服务器 VM(内部版本 20.13-b02,混合模式)
在 javac Java 6 中有一个 bug 使它工作,但是 Java 6 的其他 Java 编译器以及 [=34=34] 中的 Java 编译器=] 7+ 会抛出编译错误。
有关更多详细信息,请参阅其他 post:
Does a method's signature in Java include its return type?
http://vanillajava.blogspot.co.uk/2011/02/with-generics-return-type-is-part-of.html
编辑
@Radek 在评论部分 post编辑了另一个很好的 Whosebug post:
Method has the same erasure as another method in type
编辑 2
我想我在这里找到了错误票:
http://bugs.java.com/view_bug.do?bug_id=6182950
为什么可以用两个签名相同的方法编译 class?
"foo" 方法只有 return 种不同的类型。
但是 return 类型不是 java.
方法签名的一部分
在这种情况下,java 编译器会创建桥接方法吗?
如果是 - 真实代码会是什么样子?
foo 方法有以下警告:
Method foo(GenClass) has the same erasure foo(GenClass) as another method in type test
如果取消注释栏方法,栏方法将出现以下错误:
Method bar(GenClass) has the same erasure bar(GenClass) as another method in type test
class GenClass<T> {
}
public class test {
public static void main(String[] args) {
}
public static Integer foo(GenClass<Integer> criteria) {
System.out.println("Integer");
return null;
}
public static String foo(GenClass<String> criteria) {
System.out.println("String");
return null;
}
/*public static void bar(GenClass<Integer> criteria) {
System.out.println("Integer");
}
public static void bar(GenClass<String> criteria) {
System.out.println("String");
}*/
}
D:\tools\java\jdk1.6.0_37_32\bin>java -版本
java 版本“1.6.0_38”
Java(TM) SE 运行时环境(build 1.6.0_38-b05)
Java HotSpot(TM) 64 位服务器 VM(内部版本 20.13-b02,混合模式)
在 javac Java 6 中有一个 bug 使它工作,但是 Java 6 的其他 Java 编译器以及 [=34=34] 中的 Java 编译器=] 7+ 会抛出编译错误。
有关更多详细信息,请参阅其他 post:
Does a method's signature in Java include its return type?
http://vanillajava.blogspot.co.uk/2011/02/with-generics-return-type-is-part-of.html
编辑
@Radek 在评论部分 post编辑了另一个很好的 Whosebug post:
Method has the same erasure as another method in type
编辑 2 我想我在这里找到了错误票: http://bugs.java.com/view_bug.do?bug_id=6182950