سؤال

As explained in the answers to this question: Eclipse bug? When is a short not a short? It is not legal in a method to implicitly narrow convert an int to a short. And that was related to passing an int as an argument where the parameter in the method was a short.

However it appears that for the return type things are different.

public short doStuff(){
System.out.println("ciao");
return 4;
}

It still is in the method scope even though it is going to be assigned outside the method (maybe this is the reason why). However being a little puzzled about it, I would ask your view about it.

هل كانت مفيدة؟

المحلول

It works because it's a literal constant. This will give a compiler error:

public short doStuff(int test)
{
    System.out.println("ciao");
    return test;  // error
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top