paulirwin opened a new issue, #1062:
URL: https://github.com/apache/lucenenet/issues/1062

   ### Is there an existing issue for this?
   
   - [X] I have searched the existing issues
   
   ### Task description
   
   From reviewing code as part of fixing #715. In Java 8+, you can pass a 
lambda for an argument that is a "functional interface" type, which is an 
interface with a single abstract method (SAM). This is roughly analogous to 
delegates in .NET, although not as powerful as delegates. In Java, lambdas are 
basically just a simpler way of implementing an anonymous class for a 
functional interface. But since Lucene at the time targeted Java 7, they could 
not take advantage of this feature like we can today.
   
   Aside: Functional interfaces in modern Java _should_ have a 
`@FunctionalInterface` annotation added, although this is not a requirement. 
SAM is sufficient.
   
   We should review to see if I've missed any below, and compare to the latest 
Lucene code any interfaces or abstract classes that are still functional (have 
not had other methods added) and consider converting those to delegate types 
where it makes sense. They should still be named delegates, rather than i.e. 
`Action<T>`, just without the `I` convention for interfaces. Then, we can 
replace many "AnonymousClass" implementations in Lucene.NET with lambdas 
instead. 
   
   As an example, this entire anonymous class could be replaced with `_ => 
true`:
   
   ```c#
   private sealed class PredicateAnonymousClass : IPredicate<object[]>
   {
       public bool Apply(object[] args)
       {
           return true;
       }
   }
   ```
   
   Candidates:
   - `ITestPoint` ([SAM in latest 
Lucene](https://github.com/apache/lucene/blob/deae39b01dec5d212b365afd220f6df000899bf3/lucene/test-framework/src/java/org/apache/lucene/tests/index/RandomIndexWriter.java#L601))
   - `IReaderDisposedListener` ([`@FunctionalInterface` in latest 
Lucene](https://github.com/apache/lucene/blob/deae39b01dec5d212b365afd220f6df000899bf3/lucene/core/src/java/org/apache/lucene/index/IndexReader.java#L141))
   - `IAttributeReflector` (if generic overload is moved to an 
extension/external method; [`@FunctionalInterface` in latest 
Lucene](https://github.com/apache/lucene/blob/deae39b01dec5d212b365afd220f6df000899bf3/lucene/core/src/java/org/apache/lucene/util/AttributeReflector.java#L22))
   - `TestRandomChains.IPredicate<T>` (could be replaced with .NET's built-in 
`Predicate<T>` delegate, as this was [changed to use 
`java.util.function.Predicate` in latest 
Lucene](https://github.com/apache/lucene/blob/deae39b01dec5d212b365afd220f6df000899bf3/lucene/analysis.tests/src/test/org/apache/lucene/analysis/tests/TestRandomChains.java#L43))
   - `IAutomatonProvider` ([SAM in latest 
Lucene](https://github.com/apache/lucene/blob/deae39b01dec5d212b365afd220f6df000899bf3/lucene/core/src/java/org/apache/lucene/util/automaton/AutomatonProvider.java#L39))
   - `IndexReaderWarmer` (abstract class in Lucene.NET; [`@FunctionalInterface` 
in latest 
Lucene](https://github.com/apache/lucene/blob/deae39b01dec5d212b365afd220f6df000899bf3/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java#L5717))
   
   This will set us up for porting future `@FunctionalInterface`s in post-4.8 
Lucene as delegates and lambdas instead of interfaces and anonymous classes. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to