Nullpointer exception

前端 未结 5 1779
予麋鹿
予麋鹿 2020-12-02 01:05

There is a possiblity that this may be a dupicate question. I initialize a String variable to null.I may or may not update it with a value.Now I want to check whether this v

5条回答
  •  一生所求
    2020-12-02 01:32

    String is immutable

    @Test(expected = NullPointerException.class)
    public void testStringEqualsNull() {
        String s = null;
        s.equals(null);
    }
    
    @Test
    public void testStringEqualsNull2() {
        String s = null;
        TestCase.assertTrue(s == null);
    }
    

提交回复
热议问题