Skip to main content

Posts

Understanding lambda in Kotlin

Kotlin is very concise language. You can achieve same functionality with fewer characters compared to Java. But as an experienced developer, it was easy for me to switch from Java to Kotlin. Same might not be true for those who are new to programming. I had tough time explaining how Lambda works to a trainee who was new to programming. For instance, I was trying to explain a simple map function that maps objects of one type to another. I have two simple classes and a simple usage of map function I came up with following step by step code to explain what's actually going on. All the code snippets do the exact same thing. Converting imperative to functional code at the end. Extract the list of journals to new variable. The map function is being executed here, we can specify the round brackets to be explicit The code after map function including the curly braces is actually a lambda. I
Recent posts

JMockit : passing the mock variable

We had a really long interface, that needed to be mocked. One class's contructor had this interface object as an argument. With my traditional mocking approach, I would have written a @Mockclass that implements this interface, @Mock only the required method, and leave other methods unimplemented. Create a new instance of this mocked class. But that looked like BIG non required code. @Injectable to rescue JMockit have @Injectable annotation that you pass to test method as a parameter and define the Expectation. And thats it. Here is the code snippet