Or without the obfuscation :) def countFor(x : Int) = 2 def countFor(x : Float) = 3
On 10 September 2010 12:27, Ricky Clarkson <[email protected]> wrote: > That won't compile, but if I fix the obvious problems then you're left > with a change to which things happen. When you do new Y(3) in the > original, X's constructor that takes an int will be called. An > alteration to make this clear follows, but I am trying to point out a > difference that makes converting from (poor) Java to Scala difficult. > > class X { > public int count; > > public X(int x) { > count = 2; > } > > public X(float x) { > count = 3; > } > } > > class Y extends X { > public Y(int x) { > super(x * 2); > } > > public Y(float x) { > super(x * 2); > } > } > > class YTest { > public void testY() { > assert new Y(0.5F).count == 3 && new Y(5).count == 2; > } > } > > Ricky. > > -- > Ricky Clarkson > Java and Scala Programmer, AD Holdings > +44 1928 706373 > Skype: ricky_clarkson > > > > On Fri, Sep 10, 2010 at 12:11 PM, Kevin Wright <[email protected]> > wrote: > > easy! It does absolutely nothing, so the obvious improvement in both > > languages is not to write it at all... > > But if you absolutely must keep the interface (mocking perhaps?) then: > > class X(x: Float) { > > def this(x2: Int) = this(x2) > > } > > class Y(y: Float) extends X(y) { > > def this(y2: Int) = this(y2) > > } > > > > On 10 September 2010 12:01, Ricky Clarkson <[email protected]> > wrote: > >> > >> class X { > >> public X(int x) { > >> } > >> > >> public X(float x) { > >> } > >> } > >> > >> class Y extends X { > >> public Y(int x) { > >> super(x * 2); > >> } > >> > >> public Y(float x) { > >> super(x * 2); > >> } > >> } > >> > >> Ricky. > >> > >> -- > >> Ricky Clarkson > >> Java and Scala Programmer, AD Holdings > >> +44 1928 706373 > >> Skype: ricky_clarkson > >> > >> > >> > >> On Fri, Sep 10, 2010 at 11:57 AM, Kevin Wright < > [email protected]> > >> wrote: > >> > I'll throw down the gauntlet then... > >> > Can anyone provide an example of Java code that's can't be improved by > >> > writing it in Scala > >> > Or Scala code that can be improved by writing it in Java (but can't be > >> > improved by just rewriting within Scala) > >> > By "improve", I mean that the code is better with regards to one (or > >> > more) > >> > of the following: > >> > - readability (how quickly can another developer, familiar with the > >> > language, understand the code) > >> > - maintainability (how much work is involved in a simple refactoring) > >> > - thread safety > >> > But doesn't sacrifice any of the above qualities. > >> > > >> > > >> > On 10 September 2010 11:45, Steven Herod <[email protected]> > wrote: > >> >> > >> >> This thread would be a lot better, faster and easier to read and > reply > >> >> to if it were written in Scala. > >> >> > >> >> On Sep 10, 8:42 pm, Ricky Clarkson <[email protected]> wrote: > >> >> > Ok, conspiracy theory time! > >> >> > > >> >> > Reinier, the initiator of this thread, works on Project Lombok, > which > >> >> > uses annotation processing to add language features to Java. > >> >> > Therefore, isn't it in his interest to discourage uptake of Scala > and > >> >> > Clojure? Could he be trying to assert that all Scala users are > >> >> > fanboys to try to discourage associating oneself with Scala? > >> >> > > >> >> > Of course, I jest. > >> >> > > >> >> > Ricky. > >> >> > > >> >> > -- > >> >> > Ricky Clarkson > >> >> > Java Programmer and Scala Fanboi, AD Holdings > >> >> > +44 1928 706373 > >> >> > Skype: ricky_clarkson > >> >> > > >> >> > > >> >> > > >> >> > On Fri, Sep 10, 2010 at 11:28 AM, Wildam Martin <[email protected] > > > >> >> > wrote: > >> >> > > On Fri, Sep 10, 2010 at 10:44, Kevin Wright > >> >> > > <[email protected]> > >> >> > > wrote: > >> >> > >> But given the resistance I'm seeing to even small differences > >> >> > >> between > >> >> > >> Java/Scala syntax, I suspect that Clojure will be far too > radical > >> >> > >> for > >> >> > >> most > >> >> > >> institutionalised Java developers. > >> >> > > >> >> > > Somehow this sounds as Java developers are considered as not > being > >> >> > > very flexible - all the Scala and Clojure or whatever else > >> >> > > JVM-language programmers should remember, that most of them > >> >> > > probably > >> >> > > have been Java developers also for quite a long time. > >> >> > > >> >> > > Anyway, if it continues that way (if you need to address each > >> >> > > single > >> >> > > language-fan-boy begging for not turning a thread into trash) I > >> >> > > will > >> >> > > somewhat stop following the javaposse google group. > >> >> > > -- > >> >> > > Martin Wildam > >> >> > > >> >> > >http://www.google.com/profiles/mwildam > >> >> > > >> >> > > -- > >> >> > > You received this message because you are subscribed to the > Google > >> >> > > Groups "The Java Posse" group. > >> >> > > To post to this group, send email to [email protected]. > >> >> > > To unsubscribe from this group, send email to > >> >> > > [email protected]<javaposse%[email protected]> > . > >> >> > > For more options, visit this group > >> >> > > athttp://groups.google.com/group/javaposse?hl=en. > >> >> > >> >> -- > >> >> You received this message because you are subscribed to the Google > >> >> Groups > >> >> "The Java Posse" group. > >> >> To post to this group, send email to [email protected]. > >> >> To unsubscribe from this group, send email to > >> >> [email protected]<javaposse%[email protected]> > . > >> >> For more options, visit this group at > >> >> http://groups.google.com/group/javaposse?hl=en. > >> >> > >> > > >> > > >> > > >> > -- > >> > Kevin Wright > >> > > >> > mail / gtalk / msn : [email protected] > >> > pulse / skype: kev.lee.wright > >> > twitter: @thecoda > >> > > >> > -- > >> > You received this message because you are subscribed to the Google > >> > Groups > >> > "The Java Posse" group. > >> > To post to this group, send email to [email protected]. > >> > To unsubscribe from this group, send email to > >> > [email protected]<javaposse%[email protected]> > . > >> > For more options, visit this group at > >> > http://groups.google.com/group/javaposse?hl=en. > >> > > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "The Java Posse" group. > >> To post to this group, send email to [email protected]. > >> To unsubscribe from this group, send email to > >> [email protected]<javaposse%[email protected]> > . > >> For more options, visit this group at > >> http://groups.google.com/group/javaposse?hl=en. > >> > > > > > > > > -- > > Kevin Wright > > > > mail / gtalk / msn : [email protected] > > pulse / skype: kev.lee.wright > > twitter: @thecoda > > > > -- > > You received this message because you are subscribed to the Google Groups > > "The Java Posse" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<javaposse%[email protected]> > . > > For more options, visit this group at > > http://groups.google.com/group/javaposse?hl=en. > > > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<javaposse%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > > -- Kevin Wright mail / gtalk / msn : [email protected] pulse / skype: kev.lee.wright twitter: @thecoda -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
