Static method in an interface?

dudeim

New Member
Reaction score
22
Hey, I'm currently wanting to use a static method in an interface.
Ex:
JASS:

interface Stuff
      method randomInterfaceMethod takes nothing returns nothing defaults nothing
      static method randomStaticInterfaceMethod takes nothing returns nothing defaults nothing //so how is this possible? As this method will be the same for each struct instance it would be pointless to have it as a normal method. I'm using an interface as you don't have to call this method so it's completly optional.
endinterface

struct something extends Stuff
   static method randomStaticInterfaceMethod takes nothing returns nothing
   //do stuff
   endmethod
endstruct

struct somethingelse extends Stuff
   method randomInterfaceMethod takes nothing returns nothing
   //in this struct i'm not calling the static method only the normal method
   endmethod
endstruct

So how would I do this?
 

luorax

Invasion in Duskwood
Reaction score
67
AFAIK you can't use static methods in interfaces (at least I've never seen it anywhere and JH gives me error when I tried), but I came up with this after a little bit of thinking:

JASS:
function interface fooFunction takes nothing returns nothing

interface fooInterface
    static fooFunction func
endinterface

struct fooStructA extends fooInterface
    static method fooMethod takes nothing returns nothing
        call BJDebugMsg("foo #1 !!!!")
    endmethod
    static method onInit takes nothing returns nothing
        set thistype.func=thistype.fooMethod
        call thistype.fooMethod.execute()
    endmethod
endstruct

struct fooStructB extends fooInterface
    static method fooMethod takes nothing returns nothing
        call BJDebugMsg("foo #2 !!!!")
    endmethod
    static method onInit takes nothing returns nothing
        set thistype.func=thistype.fooMethod
        call thistype.fooMethod.execute()
    endmethod
endstruct
 

tooltiperror

Super Moderator
Reaction score
231
You could use a [ljass]delegate[/ljass], I think, with [ljass]defaults[/ljass].

JASS:
struct DEFAULT_WALK
    method walk takes nothing returns nothing
        // Do walking stuff here
        call BJDebugMsg("left, right, left right left")
    endmethod
endstruct

interface Animal
    delegate Animal defaults DEFAULT_WALK
endinterface

struct Ladybug extends Animal
endstruct

struct Tiger extends Animal
endstruct

function onInit takes nothing returns nothing
    local Tiger tiger = Tiger.create()
    local Ladybug lady = Ladybug.create()

    call tiger.walk()
    call lady.walk()
endfunction
 

dudeim

New Member
Reaction score
22
@luorax imma gonna try that thanks;)
@tooltiperror that looks to me like a normal interface as you use a normal method no static method or am I missing something?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top