Results 1 to 1 of 1
- 07-06-2012, 03:50 PM #1
Member
- Join Date
- Nov 2011
- Location
- In the country in which my username is real word...
- Posts
- 13
- Rep Power
- 0
Problem with creation of arrays of Class-instances
Hello!
I'm currently writing a little Java-game which makes use of the Reflection API to dynamically load objects at runtime.
This setup makes it a lot easier for me to work with the objects as I do not need to hard-code them into the game each time a new is created. If I create a new enemy I put it in the enemy-package, and it is ready for the game.
However, until now I've been using raw Class-instances for this, but I want to rid my code of all of Eclipse's Warnings. I can however not manage to do this in a safe way. How do the Class-class actually work?
Here are some problems I have (code + warning):
Warning: "Type mismatch: cannot convert from Class<SubclassOfSplinter> to Class<Splinter>"Java Code:Class<Splinter>[] c = new Class<Splinter>[] { SubclassOfSplinter.class, SubclassOfSplinter2.class };
Warning: "Cannot create a generic array of Class<? extends Splinter>"Java Code:Class<? extends Splinter>[] c = new Class<? extends Splinter>[] { SubclassOfSplinter.class, SubclassOfSplinter2.class };
Warning: "Type safety: Unchecked cast from Class<capture#2-of ?> to Class<? extends Tile>"Java Code:Class<? extends Tile> c = (Class<? extends Tile>)Class.forName("tiles." + tokens[0]);
Is there a way to solve these warnings and errors?
Is it possible to create an array of Splinter-type Classes which can include sub-classes of Splinter as well?
(I want to get rid of as much of the casting and unchecked warnings as possible)
Thanks in advance / Komposten
Similar Threads
-
How to paint multiple instances of class?
By Zigster in forum AWT / SwingReplies: 5Last Post: 05-29-2012, 04:32 PM -
Problem calling multiple instances of a class
By virex in forum New To JavaReplies: 1Last Post: 03-02-2010, 03:03 PM -
approx. 1000 instances of class?
By artemff in forum CLDC and MIDPReplies: 0Last Post: 01-01-2010, 07:57 PM -
Class Instances stored in an ArrayList
By Ersk in forum New To JavaReplies: 4Last Post: 12-12-2009, 04:13 PM -
Problem with class instances
By sdwinder in forum New To JavaReplies: 7Last Post: 10-21-2009, 01:25 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks