mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Getting type info dynamically
This commit is contained in:
parent
41e5f956e1
commit
1b780b2d46
@ -359,7 +359,7 @@ public abstract class OperatingSystem : GLib.Object {
|
||||
public abstract void use_computer();
|
||||
}
|
||||
|
||||
public class Ubuntu : OperatingSystem {
|
||||
public class Linux : OperatingSystem {
|
||||
public override void use_computer() { // Abstract methods must be overridden
|
||||
stdout.printf("Beep boop\n");
|
||||
}
|
||||
@ -400,6 +400,15 @@ interface Laptop { // May only contain abstracts or virtuals
|
||||
|
||||
public interface CellPhone : Collection, GLib.Object {}
|
||||
|
||||
// You can get the type info of a class at runtime dynamically.
|
||||
|
||||
bool type_info = object is TypeName; // uses "is" to get a bool
|
||||
|
||||
Type type_info2 = object.get_type();
|
||||
var type_name = type_info2.name();
|
||||
|
||||
Type type_info3 = typeof(Linux);
|
||||
Linux type_demo = (Linux) Object.new(type_info3);
|
||||
|
||||
```
|
||||
* More Vala documentation can be found [here](https://valadoc.org/).
|
||||
|
Loading…
Reference in New Issue
Block a user