- Code: Select all
def method<of T>
where T must be XXX
t = T() # error: Cannot create an instance of the variable
# type "T" because it doesn"t have the new() constraint
...
Forums
Syntax for new constraint?
2 posts
• Page 1 of 1
Syntax for new constraint?
Hi. Quick one. What's the syntax for declaring a new constraint?
call me Nev.
- nevdelap
- Posts: 61
- Location: Buenos Aires
Re: Syntax for new constraint?
rumour has it that you use callable
see Tests/240-generics/300-declare-generic-classes/602-instantiate-generic-arg.cobra
and new constraint search
This stuff should be in the (NYI) wiki pages on generics
- Code: Select all
class G1<of TArg>
where TArg must be class, callable
cue init
base.init
a = TArg() # instantiate a generic parameter
b = TArg()
assert a is not b
assert a.getHashCode
assert b.getHashCode
see Tests/240-generics/300-declare-generic-classes/602-instantiate-generic-arg.cobra
and new constraint search
This stuff should be in the (NYI) wiki pages on generics
- hopscc
- Posts: 632
- Location: New Plymouth, Taranaki, New Zealand
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 90 guests