Programming - Why does Java not have a static method interface? Is there any language that has a static method interface?
我想大声告诉你
我想大声告诉你 2017-06-12 09:26:00
0
2
921

I want the static methods of the subclass to also comply with fixed specifications and provide different functions, and
the static methods of the parent class to provide the same functions.

Why doesn't static methods in Java have integrated override and override behavior with ordinary methods? I think it's pretty good? Just because it doesn't follow some logic?

Do you know which programming language has this feature.

我想大声告诉你
我想大声告诉你

reply all(2)
漂亮男人

Just use singletons instead of statics.
In fact, object-oriented does not require statics.
Kotlin and the like support this very well.
Use companion objects or singleton objects instead of statics.
You can let the companion objects implement that interface. ,

https://kotlinlang.org/docs/r...

interface Factory<T> {
    fun create(): T
}


class MyClass {
    companion object : Factory<MyClass> {
        override fun create(): MyClass = MyClass()
    }
}
我想大声告诉你

First of all. You need to understand what a static method is in java. To a certain extent, rewriting is a manifestation of polymorphism, and static methods in Java are bound to classes. In other words, when this class is loaded, the static methods in the class are also loaded. What is the meaning of inheritance and overriding you said?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template