Advertisement Jump to content
Sign in to follow this  
Conny14156

Generics extends my baseclass can I use my baseclass functions?

This topic is 1879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

I was wondering if it possible to reach my baseclass functionality

public <T extends BaseComponent> T getComponent(Class<T> type)
	{
		for(int i = 0;i < this.componentList.size();i++)
		{
			if(this.componentList.get(i).typeName.equals(     
                                                                      type.typeName() 
                                                                     ))
			{
				return type.cast(this.componentList.get(i));
			}	
		}
		return null;
	}

in my BaseComponent I have a public string, is it possible to access it from the template?

my base class is also a abstract class if that matter?

 

Share this post


Link to post
Share on other sites
Advertisement

You can use type.isInstance() followed by type.cast(). I'm not sure "typeName" is actually necessary, it would appear to be duplicating Java's built-in reflection (object.getClass()).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!