
io.jenetics.lattices.Self Maven / Gradle / Ivy
/*
* Java Lattice Library (lattices-3.0.0.ALPHA1).
* Copyright (c) 2022-2022 Franz Wilhelmstötter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author:
* Franz Wilhelmstötter ([email protected])
*/
package io.jenetics.lattices;
/**
* This interface defines a recursive generic type {@code S}, which
* represents the type of the implementing class.
* {@code
* interface Foo> extends Self {
* // ...
* }
* }
* Using the {@code Self} interface in this case makes it clear that the generic
* type {@code T} of the interface {@code Foo} represents the concrete type of
* the class, implementing the interface {@code Foo}.
*
* If the interface is used as intended, the following generic {@code min} method
* can be implemented as a default method.
*
{@code
* interface Foo> extends Self, Comparable {
* // ...
*
* default A max(final A other) {
* return compareTo(other) > 0 ? self() : other;
* }
* }
* }
*
* @param the type of the implementing class.
*
* @author Franz Wilhelmstötter
* @since 3.0
* @version 3.0
*/
public interface Self> {
/**
* Return a reference of {@code this} object as the declared generic type
* {@code S}.
*
* @return the {@code this} reference as the generic type {@code S}
* @throws ClassCastException if the interface is not used as intended and
* {@code (this instanceof S) == false}
*/
@SuppressWarnings("unchecked")
default S self() {
return (S)this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy