java - Not returning values, from a function with non-void return type -


i read here on so how :

in c++ :

  1. not returning non-void function undefined behavior.
  2. ... analysis requires inspection of entire program, incompatible separate compilation, , not possible in general case ...

from made out of several answers on page, difficult, , infact impossible sometimes, check presence of return statement in functions. not returning non-void function left undefined behavior c++ standard.

however, heard in java, same thing reported error @ compile time.

q. understanding correct ? , how java achieves same ?


edit: clear, interested in understanding :

  1. if left undefined in c++ standard implementation difficulties related compiler, how java able achieve same.

  2. and if not difficult do, shouldn't c++ standard have defined error ?

java refusing run programs, if return value. take following (stupid) method

public boolean test() {     boolean var=true;    if(var)       return true; } 

the method return true, java still refuse accept valid. same method in c++ legal because return value.

so sum up: java refuse method, if compiler can't prove return value. reject methods return value.

c++ trust programmer return value, , blows @ runtime if programmer failed return something.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -