Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The reflection API is c# is also far more useful and easy to understand.

It's really annoying that you can't query a Java package to find out what classes it defines.



A java package is a namespace right? In .NET you can't query a namespace, but you can query a module (very rarely used) or assembly. Surely Java has something to query a jar.


There's nothing built-in quite like that. However, in normal circumstances, you can do it on top of what's in the JDK: pick a class you know is in the jar, load it as a classpath resource URL, parse that URL to find the jar, then read the jar using the built-in jar support. There are other ways to do it, eg starting from the classpath and working down. There are any number of libraries for doing this, eg:

https://github.com/lukehutch/fast-classpath-scanner


A package is the equivalent of an assembly


If this is technically incorrect, as suggested by the voting, I'd appreciate someone setting me straight.


An assembly is closer to a JAR. It is a single unit which can contain multiple namespaces. However, in the Java runtime, the package is the top-level organizational unit. In .NET, it's the assembly. The fully qualified type name in .NET contains the assembly, namespace, and type name. In Java, it's just the package and type name.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: