How to replace param “t” to “className”?

  • A+
Android Studio 3.2.1 Kotlin plugin version 1.3.11-release-Studio3.2-1 ext.kotlin_version = '1.3.11'  RxJava 1.3.0  

For example when I type in *.kt file: Observable.unsafeCreate{} and then press Ctrl+Space between {} , then IntellijIdea suggest me to type symbol t ->, but when I do the same in .java file result is subscriber -> :

*.kt file:

fun anyFunc(): Observable<Boolean>{     return Observable.unsafeCreate { t -> t } } 

How to replace param “t” to “className”?

*.java file:

public void anyFunc() {     Observable.unsafeCreate(subscriber -> {}); } 

How to make in Kotlin file the same behavior of suggestion typing like in Java file?

[UPDATE] Seems it is because of call() method in rx.functions.Func1, it has param t:

public interface Func1<T, R> extends Function {      R call(T t);  } 


Actually Intellij helps you on the Java side but not (yet) on the Kotlin side.

The subscriber-parameter-name is derived from the generic type of the extended interface, i.e. Subscriber from interface OnSubscribe<T> extends Action1<Subscriber<? super T>>.

On the Kotlin side however this mechanism isn't applied and so the code completion suggests you the parameter of the implementing function instead, which in this case is from Action1#call(T t), so just t.

You can test that it uses the generic type information by just making a basic example:

class CustomObject {} interface MyCustomConsumer extends Consumer<CustomObject> { }  static void test(MyCustomConsumer mcs) { }  public static void main(String[] args) {      test( // <- place cursor here and start code completion and you should get "customObject" 

Note that for some types it adapts the naming, e.g. String becomes s and the other boxed types (Long, Integer, etc.) are preceded by an a (e.g. aLong; of course, otherwise you would use a reserved word).

If you are curious what's happening in the source code there, you might want to go through Intellij community source code or for Android Studio you may want to go through Building Android Studio first.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: