mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
22 lines
318 B
V
22 lines
318 B
V
type Func = fn (string) string
|
|
|
|
struct Struct[T] {
|
|
a T
|
|
mut:
|
|
func Func
|
|
}
|
|
|
|
fn (st Struct[T]) foo[T](s string) string {
|
|
println('${st.a} - ${s}')
|
|
return '${st.a} - ${s}'
|
|
}
|
|
|
|
fn test_generic_method_variable() {
|
|
mut st := Struct[int]{
|
|
a: 22
|
|
}
|
|
st.func = st.foo
|
|
ret := st.func('hello')
|
|
assert ret == '22 - hello'
|
|
}
|