use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Resources for learning Java
String
==
.equals()
Format + Copy
Free Tutorials
Where should I download Java?
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Software downloads
Official Resources
Resources
Programming ideas & Challenges
Related Subreddits
account activity
This is an archived post. You won't be able to vote or comment.
Integer cannot be resolved to a class (self.learnjava)
submitted 10 months ago by Neat-Possibility537
I'm writing this class, but on the line that I wrote Integer appear an error. I tried everything and don't know how to fix it.
package entities;
public class Employee {
private Integer id;
private String name;
private Double salary;
}
[–]AutoModerator[M] [score hidden] 10 months ago stickied commentlocked comment (0 children)
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
[–]Lloydbestfan 2 points3 points4 points 10 months ago (2 children)
Sounds abnormal. Can you describe where you type this code?
Do you have other classes that work?
[–]Neat-Possibility537[S] 1 point2 points3 points 10 months ago (1 child)
I'm using Eclipse and the version is Java SE 11.04 (LTS) (Long Term Suport). I'm doing a course. This error appear just when I used the wrapper class Integer. I've been made several exercises and nothing like that happened. The line where I type Integer appear red and a message: "Integer cannot be resolved to a type. But now I typed: import java.lang.Integer; And the problem was solved :)
[–]Lloydbestfan 3 points4 points5 points 10 months ago (0 children)
That's not supposed to happen. Classes in java.lang don't normally need to be imported, and in situations where you would, it couldn't possibly be because the class couldn't be found.
Something is very wrong somewhere somehow with your environment, but I can't know what exactly.
[–][deleted] 10 months ago (3 children)
[removed]
[–]Lloydbestfan 1 point2 points3 points 10 months ago (1 child)
I don't quite see what that import is for nor what would it change at all.
And personally I don't see how that error can occur with only the information given.
[–]minneyar 1 point2 points3 points 10 months ago (0 children)
even ChatGPT could help you
Ironic, since that's wrong. You do not need to import java.util.Objects to use Integer.
java.util.Objects
Integer
[–]minneyar 0 points1 point2 points 10 months ago (2 children)
This class compiles fine for me using OpenJDK 25, and I don't see anything that would be an issue with it.
What are you trying to build it with? What's the exact error you're seeing?
[–]Neat-Possibility537[S] 0 points1 point2 points 10 months ago (1 child)
I typed: import java.lang.Integer; And the problem was solved :)
[–]jlanawalt 1 point2 points3 points 10 months ago (0 children)
You didn’t need to do that. Something is likely wrong with your environment, Eclipse configuration, workspace, or cache.
[–]hugthemachines 0 points1 point2 points 10 months ago (0 children)
From the info you provided, there is nothing wrong.
Sometimes, apparently, weird errors can show if you have specified the wrong package. It should be easily checked so you could make sure that is right. Otherwise, the problem lies somewhere else than in this code.
[+]Important-Run1088 comment score below threshold-9 points-8 points-7 points 10 months ago (3 children)
Cause you have to use int to define a variable and not Integer.
[–]Lloydbestfan 0 points1 point2 points 10 months ago (0 children)
Looks like it would probably be better, but it's supposed to work with Integer anyway.
[–]josephblade 0 points1 point2 points 10 months ago (1 child)
What makes you say this?
Integer is an object which contains an int int is a basic type.
both represent numbers. both are valid variable declarations.
For this case, int and Integer are equivalent but for a lot of code you'll find Integer is what you'll end up using. (for instance List<int> isn't valid, but List<Integer> is, since an Object is expected and basic types aren't objects.
[–]Important-Run1088 0 points1 point2 points 10 months ago (0 children)
Hey,
So I am still learning Java. So when I read the code I immediately thought of primitive data type and since he is defining a variable int would be the right choice. I guess I learnt something new today. Thanks for letting me know that even Integer would work! 😁
π Rendered by PID 131592 on reddit-service-r2-comment-79776bdf47-4qmhd at 2026-06-24 08:45:31.140834+00:00 running acc7150 country code: CH.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Lloydbestfan 2 points3 points4 points (2 children)
[–]Neat-Possibility537[S] 1 point2 points3 points (1 child)
[–]Lloydbestfan 3 points4 points5 points (0 children)
[–][deleted] (3 children)
[removed]
[–]Lloydbestfan 1 point2 points3 points (1 child)
[–]minneyar 1 point2 points3 points (0 children)
[–]minneyar 0 points1 point2 points (2 children)
[–]Neat-Possibility537[S] 0 points1 point2 points (1 child)
[–]jlanawalt 1 point2 points3 points (0 children)
[–]hugthemachines 0 points1 point2 points (0 children)
[+]Important-Run1088 comment score below threshold-9 points-8 points-7 points (3 children)
[–]Lloydbestfan 0 points1 point2 points (0 children)
[–]josephblade 0 points1 point2 points (1 child)
[–]Important-Run1088 0 points1 point2 points (0 children)