For many uses, I don't think mirrors will be that different than Java reflection. The most important thing understand about mirrors is that they decouple the reflection API from the standard object API, so instead of obj.getClass() you use reflect(obj). It's a seemingly small difference, but it gives you a few nice things:
- The object API isn't polluted, and there's no danger of breaking reflection by overriding a reflective method.
- You can potentially have different mirror systems. Say, one that doesn't allow access to private methods. This could end up being very useful for tools.
- The mirror system doesn't have to be included. For compiling to JS this can be important. If mirrors aren't used then there's no out-of-band to access code and pruning becomes viable.
- Mirrors can be made to work on remote code, not just local code, since you don't need the reflected object to be in the same Isolate or VM as the mirror.
Here's how mirrors are different than reflection in Java and Javascript when used to get an object's methods:
Java:
myObject.getClass().getMethods(); // returns an array
Dart:
reflect(myObject).type.methods; // returns a map
Javascript:
var methods = [];
for (var m in myObject) {
if (typeof m === 'function') {
methods.push(m);
}
}