-
Knowing subclasses of a class
Hi,
Is there any way in java by which i can know all the sub-classes of a given
class ( Here class can be a userdefined class or a system class). Similarly
can i know all the classes of a particular package in Java.
Regards
-
Re: Knowing subclasses of a class
"mehul joshi" <mjoshi@onebox.com> wrote:
>
>Hi,
>
>Is there any way in java by which i can know all the sub-classes of a given
>class ( Here class can be a userdefined class or a system class). Similarly
>can i know all the classes of a particular package in Java.
>
>Regards
The Java API and for user defined class documentation is the key. There
is no easy way that I know of find the information you want.
-
Re: Knowing subclasses of a class
mehul joshi <mjoshi@onebox.com> wrote in message
news:39474c17$1@news.devx.com...
>
> Hi,
>
> Is there any way in java by which i can know all the sub-classes of a
given
> class ( Here class can be a userdefined class or a system class).
Similarly
> can i know all the classes of a particular package in Java.
>
> Regards
That depends on what you mean by "i". If you want to know this, then you
should look in the documentation. But if you want a Java program to be able
to find this out, I'd suggest looking through the file system for files with
a ".class" extension. A couple of problems I foresee you having with this:
(1) you need to be able to find out what the classpath is -- is there a
system property for this? -- and watch out for the Java2 extension
mechanism, where the lib directory in the JRE is implicitly part of the
classpath (2) you need to be able to look inside .jar files in the
classpath -- they're formatted just like zip files, so you can do that.
Likewise if you want your program to know all the classes in a package, just
do the same thing for its directory path.
-
Re: Knowing subclasses of a class
"Paul Clapham" <pclapham@core-mark.com> wrote:
>
>mehul joshi <mjoshi@onebox.com> wrote in message
>news:39474c17$1@news.devx.com...
>>
>> Hi,
>>
>> Is there any way in java by which i can know all the sub-classes of a
>given
>> class ( Here class can be a userdefined class or a system class).
>Similarly
>> can i know all the classes of a particular package in Java.
>>
>> Regards
>
>That depends on what you mean by "i". If you want to know this, then you
>should look in the documentation. But if you want a Java program to be
able
>to find this out, I'd suggest looking through the file system for files
with
>a ".class" extension. A couple of problems I foresee you having with this:
>(1) you need to be able to find out what the classpath is -- is there a
>system property for this? -- and watch out for the Java2 extension
>mechanism, where the lib directory in the JRE is implicitly part of the
>classpath (2) you need to be able to look inside .jar files in the
>classpath -- they're formatted just like zip files, so you can do that.
>Likewise if you want your program to know all the classes in a package,
just
>do the same thing for its directory path.
>
>
>
>
Hi Paul,
Actually i wanted to know it programmatically (just like finding methods
of a class in Reflection).
Regards
-
Re: Knowing subclasses of a class
mehul joshi <mjoshi@onebox.com> wrote in message
news:39530e09$1@news.devx.com...
>
> "Paul Clapham" <pclapham@core-mark.com> wrote:
> >
> >mehul joshi <mjoshi@onebox.com> wrote in message
> >news:39474c17$1@news.devx.com...
> >>
> >> Hi,
> >>
> >> Is there any way in java by which i can know all the sub-classes of a
> >given
> >> class ( Here class can be a userdefined class or a system class).
> >Similarly
> >> can i know all the classes of a particular package in Java.
> >>
> >> Regards
> >
> >That depends on what you mean by "i". If you want to know this, then you
> >should look in the documentation. But if you want a Java program to be
> able
> >to find this out, I'd suggest looking through the file system for files
> with
> >a ".class" extension. A couple of problems I foresee you having with
this:
> >(1) you need to be able to find out what the classpath is -- is there a
> >system property for this? -- and watch out for the Java2 extension
> >mechanism, where the lib directory in the JRE is implicitly part of the
> >classpath (2) you need to be able to look inside .jar files in the
> >classpath -- they're formatted just like zip files, so you can do that.
> >Likewise if you want your program to know all the classes in a package,
> just
> >do the same thing for its directory path.
> >
> >
> >
> >
> Hi Paul,
>
> Actually i wanted to know it programmatically (just like finding methods
> of a class in Reflection).
>
> Regards
>
Yes, I know that's what you wanted. But the Reflection API can only reflect
on objects that have been instantiated in a program. And if you create 7
subclasses of a class, the only way for Reflection to know that would be for
you to instantiate an object of each of those 7 subclasses... which means
you already know the answer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|