title: How does android.support break Javas type safety?
body: <p>Today i encountered a very strange behavior. I know, I'm using deprecated APIs but nonetheless, this should not be possible from my understanding.</p>
  
  <p>I have a <code>android.preference.PreferenceActivity</code>in which I put the following xml via <code>addPreferenceFromResource</code>:</p>
  
  <pre><code>&lt;PreferenceScreen
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
      &lt;EditTextPreference
          android:id="@+id/et_server_endpoint"
          android:key="server_endpoint"
          android:hint="http://192.168.100.42:8080"
          android:title="Server Endpoint"
          android:summary="Sets the Server Endpoint for the search"
          android:dialogTitle="Server Endpoint Settings"
          android:dialogMessage="Set the Servers endpoint"
          /&gt;
      &lt;SeekBarPreference
          android:id="@+id/sb_phone_threshold"
          android:key="match_treshold"
          android:title="Matching Threshold"
          android:summary="Sets the minimum Score for matches"
          android:defaultValue="60"
          android:min="40"
          android:max="90"
          app:adjustable="true"
          app:showSeekBarValue="true"/&gt;  
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p>Note that <code>SeekBarPreference</code> is an <code>android.support.v7.preference.Preference</code></p>
  
  <p>I have no problem inflating the xml. The Screen shows as expected. The problem comes when I want to get a reference to it:</p>
  
  <p><code>PreferenceActivity.findPreference(key)</code> is supposed to return an <code>android.preference.Preference</code> class (which the <code>SeekBarPreference</code> is not).</p>
  
  <p>but this code returns a valid Pref:</p>
  
  <pre><code> Preference match_treshold = findPreference("match_treshold");
  </code></pre>
  
  <p>I'm not allowed to cast it:</p>
  
  <pre><code> if (match_treshold instanceof SeekBarPreference){}
  </code></pre>
  
  <p>because of </p>
  
  <blockquote>
    <p>error: incompatible types: Preference cannot be converted to SeekBarPreference</p>
  </blockquote>
  
  <p>But surprisingly, if I debug the code I get this
  <a href="https://i.stack.imgur.com/A96At.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A96At.png" alt="Debugging SeekBarPreference"></a></p>
  
  <p>It states, that the class is <code>android.preference.SeekbarPreference</code>. If I google that, all I can find is <a href="https://developer.android.com/reference/android/support/v7/preference/SeekBarPreference" rel="nofollow noreferrer">https://developer.android.com/reference/android/support/v7/preference/SeekBarPreference</a></p>
  
  <p>which states that it's based on <code>android.preference.SeekBarPreference</code>. But I cannot find this specific class.</p>
  
  <p>Beside the - from my point of view - poor design decision, to not inherit support.v7 Preferences from the Android ones: What the hell is going on there?</p>
  
  <p>EDIT: 
  Due to request I post the Activity class</p>
  
  <pre><code>package com.my.company.domain.namespace;
  
  import android.content.SharedPreferences;
  import android.os.Bundle;
  import android.preference.Preference;
  import android.preference.PreferenceActivity;
  import android.preference.PreferenceManager;
  import android.support.annotation.Nullable;
  import android.support.v7.preference.SeekBarPreference;
  import android.util.Log;
  
  public class PrefActivity extends PreferenceActivity {
  
      private SharedPreferences mPrefs;
  
      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
  
          addPreferencesFromResource(R.xml.glass_prefs);
          Preference matchTreshold = findPreference("match_treshold");
  //        code doesn't compile
  //        if (match_treshold instanceof SeekBarPreference){}
          Log.d("Pref", "onCreate: SeekBarClass=" + matchTreshold.getClass().getName());
          //prints 'android.preference.SeekBarPreference'
          //one cannot import android.preference.SeekBarPreference
      }
  }
  </code></pre>
  
  <p>you need to add </p>
  
  <blockquote>
    <p>implementation 'com.android.support:preference-v7:28.0.0'</p>
  </blockquote>
  
  <p>to the build.gradle deps</p>