Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #24610
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Wed, 03 Jul 2013 07:01:22 -0500 |
| Date | Wed, 03 Jul 2013 13:01:19 +0100 |
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
| Organization | Trollbusters 3 |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: multiple inheritance in Java |
| References | <multiple-inheritance-20130702021857@ram.dialup.fu-berlin.de> <kqtbe7$mth$1@dont-email.me> <multiple-inheritence-20130702041514@ram.dialup.fu-berlin.de> <61a00488-56ab-4452-bb3c-74e79d1a7d81@googlegroups.com> <6h8daa-4g3.ln1@s.simpson148.btinternet.com> |
| In-Reply-To | <6h8daa-4g3.ln1@s.simpson148.btinternet.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Message-ID | <hYadnW-CWvwPj0nMnZ2dnUVZ8uSdnZ2d@bt.com> (permalink) |
| Lines | 88 |
| X-Usenet-Provider | http://www.giganews.com |
| X-AuthenticatedUsername | NoAuthUser |
| X-Trace | sv3-x2H/1KglBH4xIvtdkxVrVLpYO6Jcsu9zugEnsLaO9p9lvf+19FV9MBHDOwl32ib2Zvat+o3ifseAqYV!a/AwKnEZ78YY9ulZGEHiXxi4IhHVU9vZ94esWPe/+ydxh1PUSbmZkN3ylCvSVWTF7eD/Wp+YUgc= |
| X-Complaints-To | abuse@btinternet.com |
| X-DMCA-Complaints-To | abuse@btinternet.com |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 3791 |
| Xref | csiph.com comp.lang.java.programmer:24610 |
Show key headers only | View raw
On 03/07/13 10:46, Steven Simpson wrote:
> On 02/07/13 19:53, Lew wrote:
>> WIth Java 8 don't we get default methods? You can multiply-inherit
>> interfaces.
>
> I don't see how default methods help here. You might define Position as
> an interface:
>
> interface Position {
> int getX();
> int getY();
> void setX(int x);
> void setY(int y);
> }
>
> ...but what default implementations can you give any of these methods
> without adding some state to Position?
This is an interesting question
It is possible to add state to an interface so that it is *almost* a class
The following compiles and runs on 64 bit Ubuntu Linux with
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b96)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b38, mixed mode)
javac 1.8.0-ea
I haven't figured out all the mechanics or ramifications of this yet but
it certainly looks like it is effectively possible to implement a form
of multiple inheritance in Java. Not exactly an edifying prospect.
=============================================================
/* public instance variables for brevity */
class State{
public Integer a = 0;
public Integer b = 0;
}
interface Foo{
/* explicitly static and final */
Integer i = 0;
State state = new State(); /* final reference, mutable instance */
default public void doFoo(Integer x){
//i = 10; /* illegal */
Integer y = x + i;
state.a = y + y;
System.out.println("doingFoo, i + x is " + y);
System.out.println("doingFoo, accessing state state.a is " +
state.a);
}
}
interface Bar{
Integer i = 0;
State state = new State();
default public void doBar(Integer x){
Integer y = x + i;
state.a = y + y;
System.out.println("doingBar, i + x is " + y);
System.out.println("doingBar, accessing state state.a is " +
state.a);
}
}
/* who owns the state? */
class FooBarImpl implements Foo, Bar{
}
public class Test{
public static void main(String[] args){
FooBarImpl fbi = new FooBarImpl();
fbi.doFoo(5);
fbi.doBar(10);
}
}
lipska
--
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-01 21:52 -0400
Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 00:09 -0400
Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 08:13 -0400
Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 17:33 -0400
Re: multiple inheritance in Java Sebastian <news@seyweiler.dyndns.org> - 2013-07-05 08:04 +0200
Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 13:17 -0400
Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 13:40 -0400
Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 14:29 -0400
Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 15:12 -0400
Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 17:23 -0400
Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 17:25 -0400
Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 15:44 -0400
Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 16:28 -0400
Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 16:44 -0400
Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 17:13 -0400
Re: multiple inheritance in Java Jeff Higgins <jeff@invalid.invalid> - 2013-07-02 22:12 -0400
Re: multiple inheritance in Java Lew <lewbloch@gmail.com> - 2013-07-02 11:53 -0700
Re: multiple inheritance in Java Steven Simpson <ss@domain.invalid> - 2013-07-03 10:46 +0100
Re: multiple inheritance in Java lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-07-03 13:01 +0100
Re: multiple inheritance in Java Steven Simpson <ss@domain.invalid> - 2013-07-03 14:12 +0100
Re: multiple inheritance in Java lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-07-03 14:49 +0100
Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-06 22:19 -0400
Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 17:36 -0400
Re: multiple inheritance in Java Gene Wirchenko <genew@telus.net> - 2013-07-05 11:01 -0700
csiph-web