org.hibernate.search.engine.environment.bean.InstanceBeanReference Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-search-engine Show documentation
Show all versions of hibernate-search-engine Show documentation
Hibernate Search engine, always required
The newest version!
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.search.engine.environment.bean;
import org.hibernate.search.util.common.impl.Contracts;
final class InstanceBeanReference implements BeanReference {
private final T instance;
InstanceBeanReference(T instance) {
Contracts.assertNotNull( instance, "instance" );
this.instance = instance;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[instance=" + instance + "]";
}
@Override
public BeanHolder resolve(BeanResolver beanResolver) {
return BeanHolder.of( instance );
}
@Override
@SuppressWarnings("unchecked") // Checked using reflection
public BeanReference extends U> asSubTypeOf(Class expectedType) {
// Let the type itself throw a ClassCastException if something is wrong
expectedType.cast( instance );
// The cast above worked, so we can do this safely:
return (BeanReference extends U>) this;
}
}