0

I recently inherited a bunch of code that uses Java Integer, for which I am getting a lot of compiler warnings. I would like to convert these to int to eliminate the warnings (rather than suppress them). My question is...are there any issues with simply changing Integer declarations to int? Naturally I will test the code changes, but want to know ahead of time if I will be facing any issues. I am using Java version 17.

5
  • 1
    Note that Integer is a type of object, while int is not, so if any of the code relies on one of these things being an object, that might cause an issue. Commented Nov 16, 2023 at 19:13
  • Another issue is serialization. int is program language neutral, whereas Integer is Java only. Objects are also much larger in memory than primatives Commented Nov 16, 2023 at 19:21
  • Another issue (in the realm of memory management) is that primitives that are not encapsulated as part of an object exist only on the stack, whereas Objects are all on the heap. Commented Nov 16, 2023 at 19:24
  • Your Question could be improved by posting the actual text of your compiler warnings. Commented Nov 16, 2023 at 19:27
  • If you have collectiosn like lists, that would be an issue.. Commented Nov 16, 2023 at 19:28

1 Answer 1

1

Very Yes. Integer can be null that can lead to null pointer exception. So do check before you convert to int

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.