Results 1 to 2 of 2
- 08-18-2009, 05:35 PM #1Member
- Join Date
- Jun 2007
- Rep Power
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?
- 08-21-2009, 05:31 AM #2
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.
- By arun.ranganathan in forum EclipseReplies: 0Last Post: 07-15-2009, 10:57 AM
- By Omarero in forum New To JavaReplies: 0Last Post: 03-25-2009, 06:57 PM
- By itaipee in forum AWT / SwingReplies: 1Last Post: 01-01-2009, 07:58 PM
- By haoberoi in forum New To JavaReplies: 4Last Post: 11-10-2008, 03:01 PM
- By Jothi in forum JavaServer Faces (JSF)Replies: 0Last Post: 05-20-2008, 08:50 AM