Hi Johan: a strange Java rule, indeed. Since we know it now, we can easily navigate around it. >YUCK! Can we program in ML or Haskell from now on Karl? please? We build high-level interfaces to the currently most popular programming languages and we use only the most useful subset of those programming languages. We only access data through getters. Java wins with respect to popularity. :-) Most of our undergraduate and graduate students like to use a popular language and we need to build expertise in the most useful features of those popular languages. That is why we currently use Java. -- Karl >From johan@ccs.neu.edu Sun Jul 12 18:25:30 1998 >To: dem@ccs.neu.edu, will@ccs.neu.edu, lth@ccs.neu.edu >Subject: Can anyone explain this to me >Date: Sun, 12 Jul 1998 18:25:24 -0400 >From: Johan Ovlinger >Status: R > >ARGH! > >I've been struggling with java this afternoon, and my patience is >wearing thin. I finally soved my problem, but wasn't happy with what I >learned. > >Methods are dynamically dispatched on the reciever. Fine. We expect >this. What I didn't expect is that instance variables (erm, fields) >are statically dispated on the compile time type of the receiver. This >means that if you use good OO style and use getter and setter methods for >instance variables, you're implementing a different dispatch >discipline than if you just used the instance variables. > >What's even worse is that someone designed it this way on purpose! The >only argument I can think of in favor of doing this way, is that it is >possible to override instance variables with a different type. How >useful. So that is the real reason for this mail. Can anyone propose a >useful reason for why it is this way? > >Johan > > > >Main.java (in /ccs/tmp until deleted by cron): > > class A { > String msg = "hi"; > String get_msg() {return msg;} > } > > class B extends A { > String msg = "there"; > String get_msg() {return msg;} > } > > public class Main { > public static void main(String[] args) { > A a1 = new A(); > A a2 = new B(); > B b = new B(); > > System.err.println(a1.msg+" "+a1.get_msg()); > System.err.println(a2.msg+" "+a2.get_msg()); > System.err.println(b.msg+" "+b.get_msg()); > } > } > > >vega.ccs.neu.edu(143): javac Main.java >vega.ccs.neu.edu(144): java Main >hi hi >hi there >there there > > >YUCK! Can we program in ML or Haskell from now on Karl? please? > >