Dart Virtual machine does not guarantee that the variable could not be variable but it may be a function?

122 views Asked by At

Cannot understand how variable can be a function.

Sample code.

import 'dart:mirrors';

class Foo {
 int baz;
}

void main() {
  var name = "baz=";
  var typeMirror = reflectClass(Foo);
  for(var member in typeMirror.instanceMembers.values) {
    print(MirrorSystem.getName(member.simpleName));
    if(MirrorSystem.getName(member.simpleName) == name) {
      if(member is MethodMirror) {
        print("================================");
        print("Info about METHOD $name");
        print("isSetter: ${member.isSetter}");
        print("isVariable: false, because it is a method");
        print("================================");
      }
    }
  }
}
==
hashCode
_identityHashCode
toString
noSuchMethod
runtimeType
_cid
_leftShiftWithMask32
baz
baz=
================================
Info about METHOD baz=
isSetter: true
isVariable: false, because it is a method
================================

I found this inforamtion in Wikipedia.

  • In object-oriented programming, an instance variable is a variable defined in a class (i.e. a member variable).

  • In object-oriented programming, a member variable (sometimes called a member field) is a variable that is associated with a specific class, and accessible for all its methods.

I also ask another question.

In object-oriented programming language Dart an instance variable (i.e. a member variable) is not a member of the instance? At least in the interpretation of "dart:mirrors" library.

1

There are 1 answers

9
Günter Zöchbauer On

Obviously getter and setter methods are generated automatically for public fields.

  • "baz=": isSetter == true
  • "baz": isGetter == true

I also found final Map<Symbol, MethodMirror> instanceMembers

The intent is to capture those members that constitute the API of an instance. Hence fields are not included, but the getters and setters implicitly introduced by fields are included.