Skip to content

Static methods #1847

@xushiwei

Description

@xushiwei

Basic

Go syntax:

func NewT(arg1 T1, arg2 T2, ..., argN TN) *T

t := NewT(arg1, arg2, ..., argN)

Go+ syntax:

func T.New(arg1 T1, arg2 T2, ..., argN TN) *T

t := T.new(arg1, arg2, ..., argN)

Go+ classfile syntax:

func .New(arg1 T1, arg2 T2, ..., argN TN) *T  // Or:
func T.New(arg1 T1, arg2 T2, ..., argN TN) *T

Here T.New is a normal static method. The general static method syntax is:

func T.Method(arg1 T1, arg2 T2, ..., argN TN) (ret1 R1, ret2 R2, ..., retM RM)

Typecast

explicit cast:

func T.cast(arg1 T1, arg2 T2, ..., argN TN) T

t := T(arg1, arg2, ..., argN)

implicit cast:

func T.icast(v OrigT) T

var t T = v  // var v OrigT

right cast:

func T.rcast(v T) DestT

dest := DestT(v)  // var v T

Note: Here static method cast, icast, rcast are special functions like init in Go.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions