One feature that used to be interesting to Java is that it supports anonymous internal classes, and recently discovered that JDK8 has supported lambda and has a simpler way to implement anonymous internal classes. This will make the programmer more comfortable and prefer Java. Many years ago I think Java Grammar and C # syntax is a bit far behind, without C # so easy to write, now feel jdk8 is also very good. To do the technology or to look forward.
Final TextView txtView2 = (TextView)this = (Button) Findviewbyid (R.id.btnchangetext); Btnchangeview.setonclicklistener (new View.onclicklistener () { @Override publicvoid OnClick (View v) { txtview2.settext ("Text changed"); }});
The new implementation method:
Final TextView txtView2 = (TextView)this = (Button) Findviewbyid (r.id.btnchangetext); // Btnchangeview.setonclicklistener (E-log.i ("MyTag", "button Clicked.")); assert NULL { "Btnchangeview Clicked:" + View.getid ()); Txtview2.settext (new Date (). toString ());});
Reference:
Http://stackoverflow.com/questions/37004069/errorjack-is-required-to-support-java-8-language-features
http://www.jianshu.com/p/5fc2b3362702
Configuration needs to be changed: Build.gradle
defaultConfig { ... jackOptions { enabled true } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
Apply plugin: ' Com.android.application 'Android {compilesdkversion23buildtoolsversion"24.0.2"Defaultconfig {ApplicationID"Com.firstapp.test.firstapp"minsdkversion16targetsdkversion23Versioncode1Versionname"1.0"jackoptions {enabledtrue}} buildtypes {release {minifyenabledfalseproguardfiles Getdefaultproguardfile (' Proguard-android.txt '), ' Proguard-rules.pro '}} compileoptions {sourcecompatibility1.8targetcompatibility1.8}}dependencies {Compile filetree (include: [' *.jar '], dir: ' Libs ') Testcompile' junit:junit:4.12 'Compile' com.android.support:appcompat-v7:23.4.0 '}
JDK 8 lambda expressions and examples of use in Android Studio