Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to call a method with a null parameter but have the argument not be null? [closed]

Tags:

java

In the function below, what can I use to replace <typedefinition> to make the program print "O noes!"?

public static void main(String[] args) {
    Object o = null;
    story(o);
}

private static void story(<typedefinition> o) 
{
    if (o != null)
      System.out.println("O noes!");
    else
      System.out.println("O yes");
}
like image 398
Amit Kumar Avatar asked Sep 28 '12 18:09

Amit Kumar


1 Answers

    private static void story(Object... o) 

Because if you pass null, is considered as an array (Object[]) of 1 elem (and so != null)

like image 142
obe6 Avatar answered Oct 11 '22 21:10

obe6