Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Java editor Bug for record (see following)
Java editor Bug for record [message #1871349] Mon, 23 September 2024 08:26 Go to next message
lu zhifei is currently offline lu zhifeiFriend
Messages: 1
Registered: September 2024
Junior Member
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?


Re: Java editor Bug for record [message #1871364 is a reply to message #1871349] Mon, 23 September 2024 10:32 Go to previous message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4507
Registered: July 2009
Senior Member

Have you tried placing all of your classes into a package? Is this the only error showing in the Problems View?

_
Nitin Dahyabhai
Eclipse Web Tools Platform

[Updated on: Mon, 23 September 2024 10:32]

Report message to a moderator

Previous Topic:start up issue on eclipse
Next Topic:Using different Jakarta dependency versions
Goto Forum:
  


Current Time: Sat Dec 21 17:03:21 GMT 2024

Powered by FUDForum. Page generated in 0.07425 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top