so in my constructor it has two objects as parameters and they are being assigned to variables. Do I need to check if they are null?
Asked
Active
Viewed 47 times
-3
-
assignment won't need a null check. if those variables are used further then yes , you need a null check. – Sagar Gandhi Jan 28 '16 at 06:19
-
Take a lok at this: http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it – ΦXocę 웃 Пepeúpa ツ Jan 28 '16 at 06:23
-
okay well my consturctor is public Construct(OBJ x, OBJ y) this.x = x; this.y=y; SO I would need to check if it is null Im assuming. My private attributes are objects as well – Bobby Jan 28 '16 at 06:27
1 Answers
0
Simple initialization will not given null pointer exception ,it will give null pointer exception when you are to use that variable or trying to get some value from that variable which is actually null.
For ex:
String foo = null;
int length = foo.length(); // HERE

shraddha bhardwaj
- 145
- 2
- 7