2

I'm Getting this Comment from PMD.But i have to empty the data.Is there any way to remove the content of that Object.

jayavardhan
  • 587
  • 5
  • 9
  • 19

4 Answers4

2

Setting a variable to null just removes a reference to the object. it does not change the actual object.

If you need to clean up, you most likely need to do actions to the object referenced by your variable instead.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
1

Assigning an object reference the value null does not 'empty the data'; it merely sets that variable reference to null.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
0

It probably wants you to use the Null Object pattern.

Sylvain Defresne
  • 42,429
  • 12
  • 75
  • 85
0

Just set your variable to final.

For instance, if there is the following code, SONAR will report as a code smell:

private Object obj = null;

However, if you just add final, it can be resolved.

private final Object obj = null;