Results 1 to 3 of 3
Thread: ClassCastException
- 01-13-2010, 08:25 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 10
- Rep Power
- 0
ClassCastException
Java Code:public static Object[] extendArraySize(Object[] o) { Object[] extended = new Object[o.length + 1]; System.arraycopy(o, 0, extended, 0, o.length); return extended; }When running this, I get: Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lrenamefiles.Renamer;Java Code:Renamer[] renamer = new Renamer[4]; renamer = (Renamer[]) extendArraySize(renamer);
Why do I get this?
Also, is it possible to pass a method as a parameter for another method?
For example in the use for calculating integrals.
-
You can't cast arrays like that. This looks like a situation where generics might help.
Better still: don't use arrays but rather the more flexible ArrayList which is already "genericized".
Edit: generics don't work well with arrays in that you can't create a generic array since type information doesn't exist at run time. You're far better off using an ArrayList here.Last edited by Fubarable; 01-13-2010 at 08:53 PM.
- 01-13-2010, 11:51 PM #3
your second question is can be solved by using interfaces
"There is no foolproof thing; fools are too smart."
"Why can't you solve my Problem ?"
Similar Threads
-
ClassCastException: in EJB3
By nida in forum Advanced JavaReplies: 2Last Post: 07-03-2009, 03:03 PM -
ClassCastException
By paulsim in forum Java AppletsReplies: 2Last Post: 08-21-2008, 02:14 PM -
ClassCastException in TreeSet
By pHew in forum New To JavaReplies: 2Last Post: 01-16-2008, 12:20 AM -
ClassCastException
By Ed in forum New To JavaReplies: 2Last Post: 07-04-2007, 05:26 AM -
ClassCastException
By Felissa in forum New To JavaReplies: 2Last Post: 07-04-2007, 05:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks