Java is equivalent to C # ExpandoObject

C # code example:

dynamic MyDynamic = new System.Dynamic.ExpandoObject(); MyDynamic.A = "A"; MyDynamic.B = "B"; MyDynamic.C = "C"; MyDynamic.Number = 12; MyDynamic.MyMethod = new Func<int>(() => { return 55; }); Console.WriteLine(MyDynamic.MyMethod()); 

Java :?

Any ideas why Java doesn't support this scenario?

+5
source share
1 answer

Java in this case is much more strict. So the short answer is no, Java does not have Expando. The syntax just does not support this.

However, Groovy has Expando, which is a dynamic language on top of java.

By the way, if you use Expando for testing, there are many different solutions related to Mock: EasyMock, Mockito, JMock, to name a few.

Hope this helps

+2
source

Source: https://habr.com/ru/post/1242978/


All Articles