Search code examples
jmockit

In JMockIt, what is a @Mock final parameter


I'm completely new to JMockIt. In the tutorial I see example codes that uses the final modifier for a @Mocked parameter e.g.

  @Test
   public void doSomethingHandlesSomeCheckedException(@Mocked final DependencyAbc abc) throws Exception
   {
    ...
   }

What does final mocked parameter mean here? Sometimes, "final" is not used. What is the difference?


Solution

  • This is merely a Java language issue, nothing to do with JMockit itself. For a method parameter or local variable to be used inside an inner class (anonymous or not), the Java compiler requires it to be declared as final.