Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gavr123456789/1a07652d48d4cf3147aee7b629895551 to your computer and use it in GitHub Desktop.
Save gavr123456789/1a07652d48d4cf3147aee7b629895551 to your computer and use it in GitHub Desktop.
Create an instance of type from type
class Customer: Object {
private string _firstName;
private string _surname;
public string firstName {
set { _firstName = value; prin(_firstName); }
}
public string surName {
set { _surname = value; prin(_surname); }
}
}
T sas<T>(Type type){
if (type.is_object()){
var z = Object.new(type);
return z;
} else {
T t = 0;
return t;
}
}
void main() {
Customer cust = sas(typeof(Customer));
cust.firstName = "sus";
cust.surName = "ses";
int a = sas(typeof(int));
prin(a);
}
@Miqueas
Copy link

Miqueas commented Oct 18, 2021

I think there's an error in line 16:

// `new` is a Vala keyword
var z = Object.@new(type);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment