On Tue, Feb 10, 2009 at 12:34 AM, Michael Neale <[email protected]>wrote:

>
> So how would you do it in scala ;) ?


*laugh*

Well, the Scalaposse isn't really broadcasting yet ;)


>
>
> (sorry I always find it crushing how easy everything is in scala, when
> I have to look at java).
>
> Of course you can just do:
>
> def foo() : (String, Int) = ("Hello", 42)
>
> never looking into what scala *actually* does with tuples, if its
> something nasty or not... (someone else I am sure knows if it is a
> good or bad thing).
>
>
> On Feb 10, 7:05 am, Viktor Klang <[email protected]> wrote:
> > I'd recommend putting a static factory method named "pair" aswell,
> >
> > with a bit of static import magicks:
> >
> > final Pair<String,String> values = pair("foo","bar");
> >
> > instead of
> >
> > final Pair<String,String> values = Pair.of("foo","bar");
> >
> > because
> >
> > final Pair<String,String> values = of("foo","bar"); //doesn't really make
> > sense...
> >
> > On Mon, Feb 9, 2009 at 8:30 PM, Reinier Zwitserloot <[email protected]
> >wrote:
> >
> >
> >
> >
> >
> > > .of instead of .create?
> >
> > > I likey.
> >
> > > On Feb 9, 6:26 pm, [email protected] (Dominic Mitchell) wrote:
> > > > On Mon, Feb 09, 2009 at 05:27:42AM -0800, Reinier Zwitserloot wrote:
> > > > > 1. By using a constructor, you don't get type inference. Use a
> static
> > > > > method, like so:
> >
> > > > > public static <P, Q> Pair<P, Q> create(P a, P b) {
> > > > >     return new Pair<P, Q>(a, b);
> > > > > }
> >
> > > > > and then make the actual constructor private.
> >
> > > > Hear, hear!  Although, I'd call it "of" rather than create, as that's
> > > > what the google collections library does.  The type inference leads
> to a
> > > > really nice API.
> >
> > > >   public Pair<String, Integer> doStuff() {
> > > >     // …
> > > >     return Pair.of("answer", 42);
> > > >   }
> >
> > > > As to the issues of getters / setters:
> >
> > > > * Don't have setters, pairs should be immutable.
> > > > * Do you really need to get at pairs from within JavaBeans?  I'd
> guess
> > > >   probably not.  Most of the time, the components of a pair will be
> > > >   extracted within a line or two of the call site.
> >
> > > > A nice discussion, anyways.  I wish my iPod hadn't run out of juice
> half
> > > > way through. :)
> >
> > > > -Dom
> >
> > --
> > Viktor Klang
> > Senior Systems Analyst
> >
>


-- 
Viktor Klang
Senior Systems Analyst

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to