• entries
    359
  • comments
    237
  • views
    188612

Tangent: Generic Method Bodies, Part 2

Sign in to follow this  

220 views

Yet more time yesterday, so more work into generic methods. On the slate was type parameters, using generic references as the return type and resending the generic to another generic. The example code is fairly simple today; a in-source re-creation of the C# default keyword.

Remember that Exists is the super-type of everything and that Any is the super-type of everything but void. And local variables are default initialized out of the box.


public static default => T{
local T rtn;

return(rtn);
}

public static factory => T{
return(default);
}

public static main()=>void{
default<void>;

print default<int>;
print default<decimal>;
print default;

print factory<int>;
//factory; // error as expected.
}

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now