Type aliasing Java classes with statics

后端 未结 2 608

Suppose MyClass is a class defined in Java, and has many static as well as non-static members. I tried to alias this class (and associated companion object) in a Sc

2条回答
  •  我寻月下人不归
    2021-02-15 07:06

    Although this works in pure Scala for a class + companion object, it's not possible with Java's static methods, as these don't belong to any interface.

    Scala could, in theory, create an object containing delegates to all the static methods of some class, but it doesn't do this currently. It's also possible to write a compiler plugin for this if you feel comfortable writing plugins.

    Failing that, you'll either have to create an object full of delegates yourself, or just cherry-pick a few methods and pass them around as functions.

提交回复
热议问题