java - Regarding `Variable (var-name) might not have been initialized` -


import java.io.*;  interface myioaction  {     void ioaction(reader rdr) throws ioexception; }  class myclass {     public static void main(string args[]) throws ioexception     {         reader rdr1;          int read = rdr1.read();    //statement 1          myioaction myio = (rdr2) ->          {             int ch = rdr2.read();    //statement 2         };     } } 

in above code, statement 1 produces following error

variable rdr1 might not have been initialized

whereas statement 2 compiles successfully.

so, why same error in statement 1 not produced in statement 2?

in statement 2, rdr2 in essence formal argument method. initialized when method invoked. see lambda quick start or lambda expressions tutorials more information what's going on statement 2.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -