Skip to main content

Using heritage & polymorphsime on static class, why not ?

3 replies [Last post]
alois
Offline
Joined: 2005-09-28
Points: 0

Greetings,

I just wonder to know why java doesn't support heritage & polymorphisms on static class, it's wanted ? or it's a lack of feature of the language ?

Explanation :

I have two class 'Pitbull' and 'Doberman' that extends 'Dog', each of this class have a static method call 'getAge'.

Somewhere else in an other class i'v got a method 'getFoo' that has this prototype :

public void getFoo(Class myDog)

This method receive for sure a 'Dog' class (class ! not instance !), but how to make compiler know that this class type is extended from dog and then access to static method... (from now i used dynamic compilation, but it's horrible and a lack of performance so i'm restructuring my software to use sort of proxy' to get information needed..

I dream about a syntax like that :

public void getFoo(Class myDog)

So it's lack of feature, or i doesn't understand something in language conception ?

Thanks to all,

Alois Cochard

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jwenting
Offline
Joined: 2003-12-02
Points: 0

>
> public void getFoo(Class myDog)
>
No problem, you can write that already.

> This method receive for sure a 'Dog' class (class !
> not instance !), but how to make compiler know that

it will receive an instance of Class which you assume to be an instance of Class for a class that derives from your Dog...

> public void getFoo(Class myDog)
>
> So it's lack of feature, or i doesn't understand
> something in language conception ?
>
Indeed. Usually if you don't understand why something isn't supported you don't understand the reason why it's not supported and it's NOT an omission.

alois
Offline
Joined: 2005-09-28
Points: 0

> > public void getFoo(Class myDog)
> >
> > So it's lack of feature, or i doesn't understand
> > something in language conception ?
> >
> Indeed. Usually if you don't understand why something
> isn't supported you don't understand the reason why
> it's not supported and it's NOT an omission.

Thanks for your answer, but why it's not an omission ? and what is the solution/replacement ? where is error in my conception ?

It's good to get an answer as 'yes' or 'no' but little bit more explanation can be good to understand language conception...

From that time i used dynamic compilation (something class.getMethod().invoke...) so i'm actually changing conception to use dynamic object but i want to [b]UNDERSTAND[/b]....

Thanks a lot...

alois
Offline
Joined: 2005-09-28
Points: 0

After hard relfexion i had understand that is impossible for the compiler to manage that...