Reputation: 63
I'm attempting to create a method that will return an index within an array.
private static Integer[] day1 = new Integer[6];
public Integer[] getDay1(Integer team) {
return day1[team];
}
When I try to do this, however, it highlights the opening bracket following day1 with this error.
Days.java:32: error: incompatible types: Integer cannot be converted to Integer[]
return day1[team];
^
Any idea why this is? Any help would be appreciated
Upvotes: 0
Views: 4455
Reputation: 14415
Integer
is one integer value, Integer[]
is an array of single Integer
s. The signature of your getDay1
method promises an array as return value, but you are actually returning one single element (the one at position team
).
I assume you are looking for
public Integer getDay1(Integer team) {
return day1[team];
}
Upvotes: 1
Reputation: 9847
you are returning an Integer when you have defined your method to return an array or integers, either change to
public Integer getDay1(Integer team) {
return day1[team];
}
or
public Integer[] getDay1(Integer team) {
return day1;
}
Upvotes: 1
Reputation: 249
return day1[team];
will return the team
th value of your array. However the return type of your method is Integer[] (array). Change your method to:
public Integer getDay1(Integer team) {
return day1[team];
}
Upvotes: 2