You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using an interface and not implementing the required method it compiles as long as no instance is created:
SuperStrictFrameworkBrl.Blitz
Interface IDrawable
Method Draw:Int()
End Interface
TypeTBase implements IDrawable
Field y:IntEnd Type'Local b:TBase = New TBase
Remove the comment sign above and try to compile again ...
Compile Error: Can't create instance of type TBase due to abstract Method IDrawable.Draw:Int().
[/BlitzMaxNG/tmp/untitled2.bmx;11;0]
Build Error: failed to compile (65280) /BlitzMaxNG/tmp/untitled2.bmx
Process complete
Is this "normal" behaviour? I would have expected the compiler blames it in both cases.
Now I tried to check if I can circumvent the limitation of the "Can't create instance of type TBase":
SuperStrictFrameworkBrl.BlitzImportBrl.Reflection
Interface IDrawable
Method Draw:Int()
End Interface
TypeTBase implements IDrawable
Field y:IntEnd TypeLocal b:TBase= TBase(TTypeID.ForName("TBase").NewObject())
This compiles - which won't if the check was done regardless of how a TBase-instance is created.
Edit: But as @HurryStarfish pointed out at discord, Reflection.mod was always enabling the creation of "abstract" type instances (leading to exceptions when calling the errorneous methods then)
The text was updated successfully, but these errors were encountered:
Yes, because any type that contains an abstract method implicitly becomes an abstract type, and adding Abstract to the type definition is optional in that case. TBase is abstract because it inherits Draw, which is why it complains if you try to create an instance of it.
What should however be an error is adding Final to the class, because Abstract Final types are not allowed.
When using an interface and not implementing the required method it compiles as long as no instance is created:
Remove the comment sign above and try to compile again ...
Is this "normal" behaviour? I would have expected the compiler blames it in both cases.
Now I tried to check if I can circumvent the limitation of the "Can't create instance of type TBase":
This compiles - which won't if the check was done regardless of how a TBase-instance is created.
Edit: But as @HurryStarfish pointed out at discord, Reflection.mod was always enabling the creation of "abstract" type instances (leading to exceptions when calling the errorneous methods then)
The text was updated successfully, but these errors were encountered: