java不能编译,为什么这个Java 8程序不能编译?

This program compiles fine in Java 7 (or in Java 8 with -source 7), but fails to compile with Java 8:

interface Iface {}

class Impl implements Iface {}

class Acceptor> {

public Acceptor(T obj) {}

}

public class Main {

public static void main(String[] args) {

Acceptor> acceptor = new Acceptor<>(new Impl());

}

}

Result:

Main.java:10: error: incompatible types: cannot infer type arguments for Acceptor<>

Acceptor> acceptor = new Acceptor<>(new Impl());

^

reason: inference variable T has incompatible bounds

equality constraints: Impl

upper bounds: Iface,Iface

where T is a type-variable:

T extends Iface declared in class Acceptor

where CAP#1 is a fresh type-variable:

CAP#1 extends Iface from capture of ?

1 error

In other words, this is a backwards source incompatibility between Java 7 and 8. I've gone through Incompatibilities between Java SE 8 and Java SE 7 list but did not found anything that would fit my problem.

So, is this a bug?

Environment:

$ /usr/lib/jvm/java-8-oracle/bin/java -version

java version "1.8.0"

Java(TM) SE Runtime Environment (build 1.8.0-b132)

Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

解决方案

Thanks for the report. This looks like a bug. I will take care of it and probably add a better answer once we have more information about why this is happening. I have filed this bug entry JDK-8043926, to track it.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值