Re: 1.5 generic question

From: Daniel Bonniot (Daniel.Bonniot_at_inria.fr)
Date: 12/17/03


Date: Wed, 17 Dec 2003 17:51:14 +0100


> then using generics I could define this:
>
> private List<MutableAddress> list;
>
> but could I 'down-cast' this list to do the following:
>
> List<Address> getList() { return list; }

No you can't. Otherwise, your client would be able to add an Address
which is not a MutableAddress in the list, which would make the type of
your private list field a fallacy.

So if you want such behaviour, you need to guarantee that the client
will not modify the original list. There are (at least) two ways to do
that: return a copy of the list, or return an unmodifiable version of
the list:

List<Point> get() = new ArrayList(l);

List<Point> get() = Collections.unmodifiableList(l);

These method definitions are in the syntax of Nice (the syntax = ...; is
a short-hand for { return ...; }). If expect the same idea will work in
Java 1.5, if they gave the right types to these operations, which was
not always the case as far as I could experience... Does anybody with
access to the prototype can test it?

Daniel

The Nice extension of Java: http://nice.sf.net



Relevant Pages

  • Re: VRML + JAVA + C to access position Variables
    ... Java does 3d animation and can connect to devices ... with JNI (through one programing interface) ... Internet Protocols including Client / Server ... old style VRML plug-in viewers which have many ...
    (comp.lang.java.programmer)
  • RE: Remoting and serialization
    ... if you use MarshalByRefObject for all of your "shared" objects (not ... use of interfaces and serialization. ... The decision to use Java versus .NET isn't so much about technology as it is ... you need the ENTIRE class graph for that object on your client. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: What multi-tier components to use
    ... Enterprise Java Beans. ... > with every change in the parameter list, you could make your new server ... But surely if you have an old client and the interfaces are still valid on ...
    (borland.public.delphi.thirdpartytools.general)
  • Java J2EE Openings in Phoenix, AZ, Client Will Relocate
    ... My name is Mike Vaughan and I am a recruiter for Apple Berry ... We have mutiple openings with a client of ours ... They are looking for Java, ... Duties to include preliminary and detailed design architecture, ...
    (comp.lang.java.programmer)
  • Re: Open Office Cocoa
    ... noi attualmente usiamo Flash per il playback dei Google Video ... lato client di Internet" usiamo piu` che altro ... AJAX e mi sembra che ci abbiamo fatto delle belle cosine, ... Quanto a Java client-side, non credo che Google al momento ne abbia ...
    (it.comp.macintosh)