10.1 Interface types

An interface definition introduces a type into the current scope. The interface type is described by a set of abstract method traits and a list of interfaces that it extends. This set of abstract traits must be fully implemented by any class that inherits the interface.

An interface name refers to the interface type when it is used in a type annotation or an inheritance clause of a class or interface definition.

interface I {}
class A implements I {}    // I refers to type I
var x : I  = new A         // In each of these uses too
trace( x is I )
var y : I = x as I

When a reference is bound to an interface at compile-time, the value of that reference is always the compile-time interface value, even if the interface definition would be shadowed by another property at runtime. This is shown in the following example:

interface T {}
class A implements T {}
class B {}
function f() {
    var T = B
    var x = new A
    trace(x is T)  // T refers to interface T, not var T, traces true 
}

In this example, T in the is expression refers to the outer interface T, not the inner var T.


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/specs/actionscript/3/as3_specification96.html