TransactionLock mockLock = new TransactionLock() {
    public boolean lock(String id) {
      return true;
    }
  
    public void unlock() {}
  };
transaction.setTransactionLock(mockLock);

That's an anonymous class. From Java in a Nutshell

An anonymous class is a local class without a name. An anonymous class is defined and instantiated in a single succinct expression using the new operator. While a local class definition is a statement in a block of Java code, an anonymous class definition is an expression, which means that it can be included as part of a larger expression, such as a method call. When a local class is used only once, consider using anonymous class syntax, which places the definition and use of the class in exactly the same place.

It's a common means of providing a specialisation of a base class without explicitly defining a new class via the class expression.

相关文章:

  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-29
  • 2021-06-10
  • 2021-11-01
  • 2021-06-04
  • 2022-12-23
  • 2021-10-11
  • 2022-01-19
相关资源
相似解决方案