jsr335

Java lambdas (JSR 335): Why “eliminate support for unbound inner class constructor references”?

こ雲淡風輕ζ 提交于 2020-01-23 04:57:26
问题 In the current JSR 335 draft, it's mentioned in the change log entry for 0.6.0 that it "eliminated support for unbound inner class constructor references". To illustrate, suppose you have an outer class named A and an inner class named B , and you want a function that takes an A and creates a new B instance: Function<A, A.B> foo = a -> a.new B(); Prior to 0.6.0, you can also use the constructor reference syntax to do the same thing (it's even documented in State of the Lambda): Function<A, A

Java lambdas (JSR 335): Why “eliminate support for unbound inner class constructor references”?

五迷三道 提交于 2019-12-05 00:09:06
In the current JSR 335 draft , it's mentioned in the change log entry for 0.6.0 that it "eliminated support for unbound inner class constructor references". To illustrate, suppose you have an outer class named A and an inner class named B , and you want a function that takes an A and creates a new B instance: Function<A, A.B> foo = a -> a.new B(); Prior to 0.6.0, you can also use the constructor reference syntax to do the same thing (it's even documented in State of the Lambda ): Function<A, A.B> foo = A.B::new; As mentioned above, that syntax is no longer supported in 0.6.0. I'm really

What is the reason why “synchronized” is not allowed in Java 8 interface methods?

三世轮回 提交于 2019-11-27 09:57:45
In Java 8, I can easily write: interface Interface1 { default void method1() { synchronized (this) { // Something } } static void method2() { synchronized (Interface1.class) { // Something } } } I will get the full synchronisation semantics that I can use also in classes. I cannot, however, use the synchronized modifier on method declarations: interface Interface2 { default synchronized void method1() { // ^^^^^^^^^^^^ Modifier 'synchronized' not allowed here } static synchronized void method2() { // ^^^^^^^^^^^^ Modifier 'synchronized' not allowed here } } Now, one can argue that the two

What is the reason why “synchronized” is not allowed in Java 8 interface methods?

心已入冬 提交于 2019-11-26 14:58:18
问题 In Java 8, I can easily write: interface Interface1 { default void method1() { synchronized (this) { // Something } } static void method2() { synchronized (Interface1.class) { // Something } } } I will get the full synchronisation semantics that I can use also in classes. I cannot, however, use the synchronized modifier on method declarations: interface Interface2 { default synchronized void method1() { // ^^^^^^^^^^^^ Modifier 'synchronized' not allowed here } static synchronized void

Why is “final” not allowed in Java 8 interface methods?

牧云@^-^@ 提交于 2019-11-26 06:09:23
问题 One of the most useful features of Java 8 are the new default methods on interfaces. There are essentially two reasons (there may be others) why they have been introduced: Providing actual default implementations. Example: Iterator.remove() Allowing for JDK API evolution. Example: Iterable.forEach() From an API designer\'s perspective, I would have liked to be able to use other modifiers on interface methods, e.g. final . This would be useful when adding convenience methods, preventing \