search

Home  >  Q&A  >  body text

Programming - Why does Java not have a static method interface? Is there any language that has a static method interface?

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.

我想大声告诉你我想大声告诉你2720 days ago907

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-06-12 09:28:00

    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()
        }
    }

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-06-12 09:28:00

    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?

    reply
    0
  • Cancelreply