当前位置:网站首页>@nonnull annotation of Lombok

@nonnull annotation of Lombok

2022-06-21 06:50:00 y_ bccl27

1. Why use @NonNull

NullPointerException Null pointer exception ( Be commonly called NPE abnormal ) It can be said that every developer has encountered a common exception , Even experienced veterans , I also write when I am not careful NPE Of bug. Pointer exists only in C In language ,Java There is no pointer in , A null pointer is a null reference ,Java The null pointer exception is that the reference itself is null , But called the method , At this time, a null pointer exception will appear . Member variables and methods belong to objects ( Remove static ), There are corresponding member variables and methods in the object , Then call these member variables and methods through objects . For null pointers , It doesn't point to any object , There are no so-called member variables and methods , At this time, use it to call some properties and methods , A null pointer exception will occur .

Construct a Student class , And create a full parameter constructor :

package com.bc.model;


public class Student {

    private String name;

    private Integer age;

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer 
原网站

版权声明
本文为[y_ bccl27]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210639515382.html