这两个接口都只定义了一种方法
public operator fun iterator(): Iterator<T>
Run Code Online (Sandbox Code Playgroud)
文档说Sequence是懒惰的.但是也不是Iterable懒惰(除非由a支持Collection)?
为什么会throw outerE;生成编译错误?我知道throw e;由于精确的重新抛出功能,不应该生成编译器错误.
它们是相同的Exception对象,但是一个catch仅限于块内部,一个作用于try-catch块之外.
这些都不应该生成编译器错误吗?或者,至少,两者的行为方式相同?
static void preciseRethrowTest()
{
Exception outerE;
try
{
}
catch (Exception e)
{
outerE = e;
// Compilation error here. Unhandled exception type Exception
// throw outerE;
throw e; // No compiler error
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Java 1.8.0_51.(精确的重新抛出在Java 7中引入)
static <V> void myMethod(Map<?, V> map)
{
Iterator<Entry<?, V>> it = map.entrySet().iterator();
}
Run Code Online (Sandbox Code Playgroud)
我在下面看到编译错误:
类型不匹配:无法转换Iterator<Map.Entry<capture#5-of ?,V>>为Iterator<Map.Entry<?,V>>