带有参数的 JAVA main


public class Wells {
  String str[] = null;
  static public void main(String args[]) {
    Wells objWells = new Wells();
    System.out.println(args.length);// we will NOT  get null pointer exception WHY ?
    System.out.println(objWells.str.length); // we will get null pointer exception
  }
}

在 main 方法中,参数从不为 null。

在您的对象中,您将其定义为 null,因此它将为 null

最新更新