Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: how to wrap a pre-generics library

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to wrap a pre-generics library

    I have a pre-generics library that stores different object types in Maps and Lists. The interfaces to this library are in terms of raw Maps and Lists. Is there a good way to wrap or encapsulate the classes of this library so that I can get rid of the zillions of "raw type" warnings I'm getting?

    As it happens, the Maps are all keyed on String, and the contents of these Maps and Lists all fall into a fairly limited set of types (String, Map and List).

    The best idea I've come up with is to use delegation - write (for each legacy class) a class that contains an instance of the legacy class and provides properly typed access methods. One problem with that is that the delegation would not be straightforward - the delegating methods would have to unpack the typed stuff and repack it in untyped variables on the way out to the legacy classes. They'd have to package the untyped stuff in typed variables on the way in from the legacy objects. I would really prefer not to have to set up a superclass and subclass containers for non-generic String, Map and List types...

    Hope this all makes sense to someone :-)

    FB.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: how to wrap a pre-generics library

    I'm a bit unclear as to why you want to do this...is it just to get rid of the warnings, or do you want more defined compile time type checks? For the former, you can use the @SuppressWarnings annotation. For the latter, I am not aware of a way to go about it other than wrapping it through delegation, or rewriting the library.

  3. #3
    Member
    Join Date
    Jun 2011
    Posts
    182
    My Mood
    Where
    Thanks
    15
    Thanked 8 Times in 8 Posts

    Default Re: how to wrap a pre-generics library

    I would just add the generics, if you feel it is necessary. If the Maps and Lists are all internal and still work fine, just do @SuppressWarnings and forget about it. If they are public and part of the documentation, I would change them, as it will be confusing/annoying for programmers to work with your non-generics based Map/List as opposed to what they are used to.

    EDIT:
    You could, perhaps, wrap the classes by renaming the old ones (and remove public modifier so that they are 100% internal) and then just create some new rather short generics supported classes with the previous names. The new classes could just do some simple interfacing with the old ones through type-casting and such. I think Sun might've done that with JList in JDK7... but don't quote me on that
    Last edited by bgroenks96; April 9th, 2012 at 11:02 PM. Reason: I had an idea

Similar Threads

  1. Generics.
    By Kumarrrr in forum Java Theory & Questions
    Replies: 1
    Last Post: December 6th, 2011, 06:53 PM
  2. The Concept of Entities -- Can't wrap my mind around it.
    By RaustBD in forum Java Theory & Questions
    Replies: 2
    Last Post: November 21st, 2011, 08:42 PM
  3. Need urgent help regarding java word wrap function.. URGENT
    By coldice in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 16th, 2011, 06:43 AM
  4. Generics
    By Kerr in forum Collections and Generics
    Replies: 2
    Last Post: May 19th, 2011, 07:44 PM
  5. Why wont the Button wrap?
    By Taylorleemusic in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 1st, 2010, 01:03 AM

Tags for this Thread