type code in eclipse 202406/2024/09
--
public record MiddleStudent(
String name, Integer age, String gender
) {
}
public class Ld_____502 {
private MiddleStudent[] room;
public Ld_____502() {
this.room = new MiddleStudent[10];
}
public void add(MiddleStudent student) {
expand();
for (int i = 0; i < room.length - 1; i++) {
if (this.room[i] == null) {
this.room[i] = student;
return;
}
}
System.out.println("over size");
}
private void expand(){
if (this.room[this.room.length-1] != null) {
MiddleStudent[] temp = new MiddleStudent[this.room.length + 10];
for (int i = 0; i < this.room.length; i++) {
temp[i] = this.room[i];
}
this.room = temp;
}
}
public static void main(String[] args) {
Ld_____502 list = new Ld_____502();
list.add(new MiddleStudent("Lily", 18, "g"));
BiConsumer<Ld_____502, MiddleStudent> consumer = Ld_____502::add;
consumer.accept(list, new MiddleStudent("Lbj", 19, "b"));
consumer.accept(list, new MiddleStudent("clc", 16, "g"));
consumer.accept(list, new MiddleStudent("kd", 16, "b"));
for (MiddleStudent middleStudent : list.room) {
if(middleStudent != null){
System.out.println(middleStudent);
}
}
}
/*record MiddleStudent(
String name, Integer age, String gender
) {
}*/
}
first step: run Ld_____502.main() ,it works .
second step: change Ld_____502.main(), such as add one line as following( Magicmask):
public static void main(String[] args) {
Ld_____502 list = new Ld_____502();
list.add(new MiddleStudent("Lily", 18, "g"));
BiConsumer<Ld_____502, MiddleStudent> consumer = Ld_____502::add;
consumer.accept(list, new MiddleStudent("Lbj", 19, "b"));
consumer.accept(list, new MiddleStudent("clc", 16, "g"));
consumer.accept(list, new MiddleStudent("kd", 16, "b"));
consumer.accept(list, new MiddleStudent("Magicmask", 16, "b"));
for (MiddleStudent middleStudent : list.room) {
if(middleStudent != null){
System.out.println(middleStudent);
}
}
}
then ,we'll see some strange :compile error
MiddleStudent cannot be resolved to a type
why?
bug or misuse?