I don't see a good case either, but the "strongly dynamic" folks would probably suggest situations like creating a remote proxy. If you have a transparent remote proxy for object of class C, then it might make sense for the proxy to tell that its type is C.
Myself:
- I don't think it is a good idea just in principle.
- I can't create a Type object. I would have to instantiate C and get its type from it.
- But I would also like the proxy to implement C's interface -- which, for now, immediately leads to compile-time code generation. (Me not like AOT code generation. Me sad.)
- And in the end, I can always reveal the truth via mirrors.
On the other hand, overriding runtimeType is unlikely to break anything and it will be relatively rare, I assume, so why forbidding it? It's a part of Dart's dynamic nature (same like you can't prevent subclassing).
LT
> Feature is very good for various kinds of abuse. "runtimeType" is a property of every object. I tried to assign it all types of values (not strings) - it worked. It's not necessarily final (non-final works, too).
> So, you have a loophole that allows you to associate a piece of data with every object with no hassle.
There's an official way of doing this, the Expando class. A little bit more hassle, as you put it, but it lets you do that many times in a controlled manner.
LT
Hi Dartisans,I see that it's possible to override runtimeType, like this:class Foo {final runtimeType;Foo() : runtimeType = 'whateves';}Are there any good examples of benefiting from this behavior?
Why is runtimeType not "locked down" in some way?
When would a class want to "lie" about this?
Lanesa Stubbs Spirit Flames Web Design & Development http://www.spiritflames.com http://www.twitter.com/lanesa http://www.facebook.com/lanesa Phone: 561.702.5240
On Tue, Feb 19, 2013 at 7:17 PM, Alex Tatumizer <tatu...@gmail.com> wrote:
> ... so you can't use type tests or casts to discover it is a proxy.
But now you CAN use type tests to discover it's a proxy, e.g:
class Bar {}
class Foo {
final runtimeType;
Foo(): runtimeType=new Bar().runtimeType;print(foo is Bar);
}
void main() {
var foo=new Foo();
print(foo is Foo); // foo is still Foo!
}
prints
false
true
And I didn't really use any mirrors or anything. What gives?You're not trying hard enough to be a secret Bar imposter.First of all, hide the Foo class from anyone who knows about Bar, so they can't do "x is Foo".Then *be* a Bar.class Bar {int foo() => 42;}class _BarProxy implements Bar {
Type get runtimeType => Bar;int foo() {log("YOU CALLED FOO");return 42;}}Then, given an instance of _BarProxy, but without knowing about that class, can you see that it is not really an instance of Bar?/L--Lasse R.H. Nielsen - l...@google.com'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K - Denmark - CVR nr. 28 86 69 84
--
Ok how do i remove myself from these emails... I can't seem to find out how i got added?
So then you have to do something with myBarType, but what exactly? Why did you need it in the first place?
in dart, runtimeType is roughly equivalent to java's getClass(), and there are situations where you need it in java, but all such situations I can remember at the moment are related to reflection (so you retrieve getClass not for fun, but to use reflection in some or other way).
So, could anyone describe the situation when you REALLY need to retrieve runtime type, without the intent of using reflection?
Now that I finally understand what you people are talking about, I feel even more confused. I can't find a good use case for this contraption.
All clear. Easy way to solve complex problem.I wonder how do respond standalone VM, if I substitute types and pass this "proxied" object back to VM?
For example, int type.
I wonder how do respond standalone VM, if I substitute types and pass this "proxied" object back to VM?
For example, int type.