I'm trying to make a class schedule in Java for my course final project, but I'm getting some troubles. I need a way to store a pointer of an object (object of type CourseClass or Class) in a Hashmap or other Map interface of Java.
To solve the problem of many classes in many rooms in the same space-time, I created a "Class" vector (founded here )
// Hours per day * days per week * number_of_rooms
CourseClass[] schedule = new CourseClass[12 * 5 * number_of_rooms];
Well, now I need store where a class start. I can do something like:
HashMap <CourseClass, Integer> = ...
But it will store another CourseClass object, and that isn't what I want (or what I need..), I just want a pointer to the already created CourseClass object.
Someone have a good tip to solve my problem?
Java's maps store only references to objects.
Your HashMap<CourseClass,Integer>
won't store another CourseClass object. Each entry in the map will store a reference to a CourseClass, and a reference to an Integer. Those objects may have other references pointing to them.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.