Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it legal to extend the Class class?
    primarykey
    data
    text
    <p>I've been writing a system that <strong>at runtime</strong> generates some templates, and then generates some objects based on those templates. I had the idea that the templates could be extensions of the Class class, but that resulted in some magnificent errors:</p> <pre><code>VerifyError: Error #1107: The ABC data is corrupt, attempt to read out of bounds. </code></pre> <p>What I'm wondering is if subclassing Class is even possible, if there is perhaps some case where doing this would be appropriate, and not just a gross misuse of OOP. I believe it should be possible, as ActionScript allows you to create variables of the Class type. This use is described in the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Class.html" rel="nofollow noreferrer">LiveDocs entry for Class</a>, yet I've seen no mentions of subclassing Class.</p> <p>Here's a pseudocode example:</p> <pre><code>class Foo extends Class var A:Foo = new Foo(); // A is a class trace(A is Class); // true, right? var b = new A(); // b is an instance of class A </code></pre> <p>I have no idea what the type of <code>b</code> would be. Would it be this?</p> <pre><code>trace(b is A); // true? </code></pre> <p>But then, could you type the variable <code>b</code> to type <code>A</code>, as in <code>var b:A = new A();</code>, even though <code>A</code> doesn't exist until runtime? I have read that this is not possible as <code>A</code> is not statically resolvable, but I am doing my own tests to explore this possibility.</p> <p>Ultimately, the purpose is to generate new classes <strong>at runtime</strong>, and to then create instances of those classes.</p> <p>In summary: can you subclass the Class class? If so, how can you do it without errors, and what type are the instances of the instances of the Class subclass?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload