I'm a .NET guy - and I mainly code in C#.
Since C# 3.0, we can leverage lambda expressions and expression trees to use static reflection. For example, it is possible to implement GetMethodName
in the following snippet to return the name of the method passed in parameter:
string methodName = GetMethodName( o => o.DoSomething());
Console.WriteLine(methodName); // displays "DoSomething"
Now, when I look at Mockito samples (or EasyMock ones) in the java world, I see:
LinkedList mockedList = mock(LinkedList.class);
when(mockedList.get(0)).thenReturn("first");
How does it work?
How does the when
method work ? How does it interpret mockedList.get(0)
as a call to the get method with 0 passed as parameter and not as a value?