What methods should go into a java.util.Objects class in JDK 7?

Ulf Zibis Ulf.Zibis at gmx.de
Thu Sep 10 11:07:16 UTC 2009


Am 10.09.2009 05:45, Reinier Zwitserloot schrieb:
>
> A trick I'm reverting to rather a lot of late is to find my own jar 
> file by getting a URL to my own class file as a resource, resolved 
> against my own class, and then parsing this URL for the jar bit of it. 
> (MyClassName.class.getResource("MyClassName.class")). There are a 
> bunch of caveats here, mostly revolving around the notion that you may 
> not have been loaded as a jar file, but as a directory, or via the 
> network, or from a database, or who knows how? - but that's what 
> returning "null" is for, surely. Something to consider, though I'm not 
> entirely convinced this hack should be made legitimate by turning it 
> into a library method. I doubt it's a good fit for Objects, in any case.

I guess you mean:
MyClassName.class.getResource("MyClassSimpleName.class")

I would like File(URI uri) to accept jar URI's, so it would be possible 
to get a nio channel access to a jared resource.

Or even better:
MyClassName.class.getResourceAsChannel("MyResourceName"))

-Ulf





More information about the core-libs-dev mailing list