I am developing an application on both iOS and Android. I want to check what is the equivalent data type similar to Objective-C’s “id” in Java (android), like how ‘id’ supports dynamic binding and typing.
Could someone guide me, since i could’t find answer for this yet?
There’s no duck typing in Java, so one cannot call arbitrary method of arbitrary object in Java, hence there’s no such magic type like
id.One must explicitly cast to desired type and only then call desired method.
However there’s
invokedynamicintroduced in Java 7, but I’m not sure you can use it directly in Java code right now.I’ll advise to analyze cases where you need that duck typing
idmagic and think how to avoid it.