English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Ok, what I'm trying to do is make a static method that passes in an array object (no matter the type, so it can be a class that's user written) and returns an array type. Whenever I try and compile the drivers, it says incompatible type. :( HELP!
There is nothing wrong with the method.

Method
public static Object[] deleteIndex(Object[] arr, int Index)

error thrown in driver at:
list2 = arrayFix.deleteIndex(list2, 2);

testArray.java:XX: incompatible types
found : java.lang.Object[ ]
required: Die[ ]
list2 = arrayFix.deleteIndex(list2, 2);

list2 is an array of type Die.

The driver only has a problem at this point. If I take it out, it compiles.

2007-02-08 08:13:59 · 2 answers · asked by David Calisuni 2 in Computers & Internet Programming & Design

I did not do any casting. Can you give an example? I don't know how to do that.

2007-02-08 10:56:20 · update #1

2 answers

Casting types around; Object is a generic type, Java has restored Template into its language to solve this problem in new versions but since I was in college before that kind of change I am nore comfortable with casting around. You obviously did not do casting to have this error.

2007-02-08 08:36:53 · answer #1 · answered by Andy T 7 · 1 0

Object[ ] is simply an array of Objects, which is the base class for all objects/classes in Java.

list2 would need to be defined as something like:

Object[] list2 = new Object[10];
list2[0] = new String("Hello");
list2[1] = new Integer(59);
list2[2] = new Double(3.1415926536);
....

2007-02-09 00:13:53 · answer #2 · answered by KnightSpot 2 · 0 0

fedest.com, questions and answers