Results 1 to 2 of 2
  1. #1
    johann_p is offline Member
    Join Date
    Jun 2007
    Posts
    19
    Rep Power
    0

    Default How can I extend java.net.URI - why is it final?

    I am working on an ontology-related library and I am struggling with this problem: java.net.URI is final and therefore I cannot extend it.
    Why on earth is it final?
    And how can I work around this?

    The problem is this: people who want to use that library already will be using java.net.URIs all over the place. So my methods should be able to accept java.net.URI as parameters.
    However, the library should also be able to deal with IRIs (which are an extension of URIs in that they allow certain parts of the URI to be UTF-8 encoded) and Nodes (which in turn are an extension of IRIs in that Nodes alternatively can represent IRIs or blank nodes that have a blank node identifier).

    The ideal way to do this would be to have the methods accept java.net.URI or some extension of it.

    But with URI being defined final this does not seem to be possible.

    So again: how does one solve this dilemma and why on earth is URI final?

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    URI is final because it represents a highly standardized entity that the Java implementers don't anyone to change. You do have a couple of options.

    One is simply to overload your methods so that they accept URI or something else in its place. Good practice is to have the overloaded methods call one method, perhaps a private method, that contains the logic they share.

    From the bit you said, I think this solution will work well. I don't think extending URI would really help you in the long run.

    You can also wrap URI and make it accessible in your class, but I don't think that will help you in your case.

Similar Threads

  1. Override/Extend Eclipse Class Loading
    By arun.ranganathan in forum Eclipse
    Replies: 0
    Last Post: 07-15-2009, 10:57 AM
  2. extend a button
    By Omarero in forum New To Java
    Replies: 0
    Last Post: 03-25-2009, 06:57 PM
  3. using J-classes or extend them ?
    By itaipee in forum AWT / Swing
    Replies: 1
    Last Post: 01-01-2009, 07:58 PM
  4. [SOLVED] is final class members are also final ?
    By haoberoi in forum New To Java
    Replies: 4
    Last Post: 11-10-2008, 03:01 PM
  5. How to extend Messages Component
    By Jothi in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 05-20-2008, 08:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •