Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #27398 > unrolled thread
| Started by | Wayne <nospam@all.invalid> |
|---|---|
| First post | 2014-01-26 04:55 -0500 |
| Last post | 2014-01-26 20:37 -0500 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
Java 8 question about default and static methods in interfaces Wayne <nospam@all.invalid> - 2014-01-26 04:55 -0500
Re: Java 8 question about default and static methods in interfaces Arne Vajhøj <arne@vajhoej.dk> - 2014-01-26 07:56 -0500
Re: Java 8 question about default and static methods in interfaces Arne Vajhøj <arne@vajhoej.dk> - 2014-01-26 13:12 -0500
Re: Java 8 question about default and static methods in interfaces Wayne <nospam@all.invalid> - 2014-01-26 20:37 -0500
| From | Wayne <nospam@all.invalid> |
|---|---|
| Date | 2014-01-26 04:55 -0500 |
| Subject | Java 8 question about default and static methods in interfaces |
| Message-ID | <JX4Fu.281210$2R1.21049@fx13.iad> |
Consider the following Java 8 interfaces:
public interface Foo {
default void method () {
System.out.println("Foo.method");
}
}
public interface Bar extends Foo {
default void method () {
System.out.println("Bar.method");
}
}
The question is, can Foo.method be used from Bar.method?
In other words, is the following version of Bar legal?
public interface Bar extends Foo {
default void method () {
super.method();
System.out.println("Bar.method");
}
}
I didn't see a reference in the docs I used, if static
methods can be redefined as well. Does anyone know?
I'd appreciate a link I could use for a better reference
than the Oracle Java Tutorial.
--
Wayne
[toc] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2014-01-26 07:56 -0500 |
| Message-ID | <52e505e8$0$294$14726298@news.sunsite.dk> |
| In reply to | #27398 |
On 1/26/2014 4:55 AM, Wayne wrote:
> public interface Foo {
> default void method () {
> System.out.println("Foo.method");
> }
> }
> public interface Bar extends Foo {
> default void method () {
> System.out.println("Bar.method");
> }
> }
>
> The question is, can Foo.method be used from Bar.method?
> In other words, is the following version of Bar legal?
>
> public interface Bar extends Foo {
> default void method () {
> super.method();
> System.out.println("Bar.method");
> }
> }
Well - the following compiles and run with Java 8 EA something:
public class DefMet {
public static void main(String[] args) {
Bar o = new C();
o.method();
}
}
class C implements Bar {
}
interface Foo {
default void method () {
System.out.println("Foo.method");
}
}
interface Bar extends Foo {
default void method () {
Foo.super.method();
System.out.println("Bar.method");
}
}
Note the use of Foo.super instead of just super.
Arne
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2014-01-26 13:12 -0500 |
| Message-ID | <52e54ff2$0$295$14726298@news.sunsite.dk> |
| In reply to | #27399 |
On 1/26/2014 7:56 AM, Arne Vajhøj wrote:
> On 1/26/2014 4:55 AM, Wayne wrote:
>> public interface Foo {
>> default void method () {
>> System.out.println("Foo.method");
>> }
>> }
>> public interface Bar extends Foo {
>> default void method () {
>> System.out.println("Bar.method");
>> }
>> }
>>
>> The question is, can Foo.method be used from Bar.method?
>> In other words, is the following version of Bar legal?
>>
>> public interface Bar extends Foo {
>> default void method () {
>> super.method();
>> System.out.println("Bar.method");
>> }
>> }
>
> Well - the following compiles and run with Java 8 EA something:
>
> public class DefMet {
> public static void main(String[] args) {
> Bar o = new C();
> o.method();
> }
> }
>
> class C implements Bar {
> }
>
> interface Foo {
> default void method () {
> System.out.println("Foo.method");
> }
> }
>
> interface Bar extends Foo {
> default void method () {
> Foo.super.method();
> System.out.println("Bar.method");
> }
> }
>
> Note the use of Foo.super instead of just super.
Syntax must be intended for:
public class DefMet2 {
public static void main(String[] args) {
Bar o = new C();
o.method();
}
}
class C implements Foo, Bar {
public void method() {
Foo.super.method();
Bar.super.method();
System.out.println("C.method");
}
}
interface Foo {
default void method () {
System.out.println("Foo.method");
}
}
interface Bar {
default void method () {
System.out.println("Bar.method");
}
}
Arne
[toc] | [prev] | [next] | [standalone]
| From | Wayne <nospam@all.invalid> |
|---|---|
| Date | 2014-01-26 20:37 -0500 |
| Message-ID | <0LiFu.157075$JL1.152266@fx08.iad> |
| In reply to | #27400 |
On 1/26/2014 1:12 PM, Arne Vajhøj wrote:
> On 1/26/2014 7:56 AM, Arne Vajhøj wrote:
>> On 1/26/2014 4:55 AM, Wayne wrote:
>>> public interface Foo {
>>> default void method () {
>>> System.out.println("Foo.method");
>>> }
>>> }
>>> public interface Bar extends Foo {
>>> default void method () {
>>> System.out.println("Bar.method");
>>> }
>>> }
>>>
>>> The question is, can Foo.method be used from Bar.method?
>>> In other words, is the following version of Bar legal?
>>>
>>> public interface Bar extends Foo {
>>> default void method () {
>>> super.method();
>>> System.out.println("Bar.method");
>>> }
>>> }
>>
>> Well - the following compiles and run with Java 8 EA something:
>>
>> public class DefMet {
>> public static void main(String[] args) {
>> Bar o = new C();
>> o.method();
>> }
>> }
>>
>> class C implements Bar {
>> }
>>
>> interface Foo {
>> default void method () {
>> System.out.println("Foo.method");
>> }
>> }
>>
>> interface Bar extends Foo {
>> default void method () {
>> Foo.super.method();
>> System.out.println("Bar.method");
>> }
>> }
>>
>> Note the use of Foo.super instead of just super.
>
> Syntax must be intended for:
>
> public class DefMet2 {
> public static void main(String[] args) {
> Bar o = new C();
> o.method();
> }
> }
>
> class C implements Foo, Bar {
> public void method() {
> Foo.super.method();
> Bar.super.method();
> System.out.println("C.method");
> }
> }
>
> interface Foo {
> default void method () {
> System.out.println("Foo.method");
> }
> }
>
> interface Bar {
> default void method () {
> System.out.println("Bar.method");
> }
> }
>
> Arne
>
>
Thanks!
--
Wayne
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web