title: Method references in Android Studio
body: <p>I am attempting to use a Java 8 feature in Android Studio. Specifically method references. To be even more specific, a reference to an instance method of a particular object. To use the wording the <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html" rel="nofollow noreferrer">Oracle docs page</a>.</p>
  
  <p>My offending code is this. The relevant methods are initTablet, and doStuff which is a dummy method I'm using to figure this out.</p>
  
  <pre><code>public class SettingsPresenter {
  
      SettingsFragment fragment;
      DeviceModel deviceModel;
  
      public SettingsPresenter(SettingsFragment fragment) {
          this.fragment = fragment;
          Context appContext = fragment.getActivity().getApplicationContext();
          deviceModel = new DeviceModel(appContext);
      }
  
      public boolean showTabletInit() {
          Map&lt;String, String&gt; creds = deviceModel.getServerCredentials();
          if (creds.get("pname").isEmpty() || creds.get("pvalue").isEmpty()) {
              return true;
          }
          return false;
      }
  
      public int doStuff() {
          return 1;
      }
  
      public void initTablet(String tokenId) {
          Log.d("debug", tokenId);
          deviceModel.initServerCredentials(tokenId, this::doStuff);
      }
  }
  </code></pre>
  
  <p>The error is being highlighted at </p>
  
  <pre><code>deviceModel.initServerCredentials(tokenId, this::doStuff);
  </code></pre>
  
  <p>with "this::doStuff" showing the cannot resolve method error.</p>
  
  <p>I followed the steps <a href="https://developer.android.com/studio/write/java8-support.html" rel="nofollow noreferrer">Android Java 8 support page</a>. And so have the following values in my Project Structure:</p>
  
  <ul>
  <li>Compile Sdk Version: API 25: Android 7.1.1 (Nougat)</li>
  <li>Build Tools Version 26.0.2</li>
  <li>Source Compatibility 1.8</li>
  <li>Target Compatibility 1.8</li>
  </ul>
  
  <p>My build.grandle looks like this</p>
  
  <p>apply plugin: 'com.android.application'</p>
  
  <pre><code>android {
      compileSdkVersion 25
      buildToolsVersion "26.0.2"
      defaultConfig {
          applicationId "com.hoistiq.machinelog"
          minSdkVersion 25
          targetSdkVersion 25
          versionCode 2
          versionName "0.1.1"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_8
          targetCompatibility JavaVersion.VERSION_1_8
      }
  }
  
  dependencies {
      implementation 'com.android.support:recyclerview-v7:25.1.0'
      compile fileTree(include: ['*.jar'], dir: 'libs')
      androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
          exclude group: 'com.android.support', module: 'support-annotations'
      })
      compile 'com.android.support:appcompat-v7:25.1.0'
      compile 'com.android.support:support-v4:25.1.0'
      compile 'com.android.support:design:25.1.0'
      compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
      compile 'com.google.code.gson:gson:2.4'
      compile 'com.android.volley:volley:1.0.0'
      compile 'com.google.android:flexbox:0.2.5'
      testCompile 'junit:junit:4.12'
  }
  </code></pre>
  
  <p>This is all on Android Studio 3.0.
  Thank you.</p>