Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Generics extends my baseclass can I use my baseclass functions?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 Conny14156   Members   

279
Like
0Likes
Like

Posted 30 November 2013 - 09:12 AM

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?

 



#2 rip-off   Moderators   

10890
Like
0Likes
Like

Posted 30 November 2013 - 12:13 PM

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()).






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.