Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #24568 > unrolled thread

Re: multiple inheritance in Java

Started byEric Sosman <esosman@comcast-dot-net.invalid>
First post2013-07-01 21:52 -0400
Last post2013-07-05 11:01 -0700
Articles 4 on this page of 24 — 8 participants

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#24612

Fromlipska the kat <"nospam at neversurrender dot co dot uk">
Date2013-07-03 14:49 +0100
Message-ID<Zq6dnQkaj4dPtknMnZ2dnUVZ7tqdnZ2d@bt.com>
In reply to#24611
On 03/07/13 14:12, Steven Simpson wrote:
> On 03/07/13 13:01, lipska the kat wrote:
>> It is possible to add state to an interface so that it is *almost* a
>> class [...]
>>
>> 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);
>>    }
>> }
>
> Foo.state is effectively class state, rather than instance state, isn't
> it?  Some possibilities were discussed here:
>
> <http://mail.openjdk.java.net/pipermail/lambda-dev/2012-July/005165.html>

I don't know, I've only recently started looking at this.
IIUC (which is by no means certain at this point) then state is a class 
variable that is shared by all instances of all classes that implement 
the Foo interface ... or is it a class variable that is shared by all 
instances of a given class that implements Foo and a different class 
that implements Foo would have it's own copy of state shared by all it's 
instances ... that seems more likely, I suppose some more investigation 
is required

I can't say I've ever really had much use for variables in interfaces 
before so I've never really given this sort of thing much thought.

lipska

-- 
Lipska the Kat©: Troll hunter, sandbox destroyer
and farscape dreamer of Aeryn Sun

[toc] | [prev] | [next] | [standalone]


#24688

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-07-06 22:19 -0400
Message-ID<51d8d053$0$298$14726298@news.sunsite.dk>
In reply to#24610
On 7/3/2013 8:01 AM, lipska the kat wrote:
> 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);
>      }
> }

Foo own its state and Bar own its state and FooBarImpl
owns nothing.

Slightly different example:

public class StateTest {
     public static void main(String[] args) {
         System.out.println(Foo.state);
         System.out.println(Bar.state);
         FooBarImpl o = new FooBarImpl();
         o.doFoo();
         o.doBar();
     }
}

interface Foo {
     int state = 123;
     public default void doFoo() {
         System.out.println(Foo.state);
         System.out.println(Bar.state);
         System.out.println(state);
     }
}

interface Bar {
     int state = 456;
     public default void doBar() {
         System.out.println(Foo.state);
         System.out.println(Bar.state);
         System.out.println(state);
     }
}

class FooBarImpl implements Foo, Bar {
     public void m() {
         System.out.println(Foo.state);
         System.out.println(Bar.state);
         // does not compile because state is ambiguous:
         //System.out.println(state);
     }
}

Arne


[toc] | [prev] | [next] | [standalone]


#24636

FromArne Vajhøj <arne@vajhoej.dk>
Date2013-07-04 17:36 -0400
Message-ID<51d5eaf9$0$302$14726298@news.sunsite.dk>
In reply to#24568
On 7/1/2013 10:16 PM, Stefan Ram wrote:
> Eric Sosman <esosman@comcast-dot-net.invalid> writes:
>>      Also, what are Position and Color?
>
>    Classes whose objects represent what is the English meaning
>    of position and color of a pixel, i.e., x and y, and r, g,
>    and b. I was hoping that this might become clear from the
>    examples given.

That is how real people think.

Homo sapiens programmaticus is a weird species that gets distracted
by class names with real meaning in language discussions and therefor
Foo, Bar and FooBar are often better in that context.

:-)

Arne

[toc] | [prev] | [next] | [standalone]


#24657

FromGene Wirchenko <genew@telus.net>
Date2013-07-05 11:01 -0700
Message-ID<cb2et858eka2e5njnqeoc1lsgms811i5n2@4ax.com>
In reply to#24636
On Thu, 04 Jul 2013 17:36:54 -0400, Arne Vajhøj <arne@vajhoej.dk>
wrote:

>On 7/1/2013 10:16 PM, Stefan Ram wrote:
>> Eric Sosman <esosman@comcast-dot-net.invalid> writes:
>>>      Also, what are Position and Color?
>>
>>    Classes whose objects represent what is the English meaning
>>    of position and color of a pixel, i.e., x and y, and r, g,
>>    and b. I was hoping that this might become clear from the
>>    examples given.
>
>That is how real people think.
>
>Homo sapiens programmaticus is a weird species that gets distracted
>by class names with real meaning in language discussions and therefor
>Foo, Bar and FooBar are often better in that context.
>
>:-)

     Some of them can get so caught up in it that there is a real
question whether they are of the same species and whether they should
be classed as homo programmaticus.  This is much as whether
Neanderthal man should be homo sapiens neanderthalensis or homo
neanderthalensis.

     People are people, but programmers are something else.

<VBEG>

Sincerely,

Gene Wirchenko

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.java.programmer


csiph-web