All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.landawn.abacus.util.TypeReference Maven / Gradle / Ivy

Go to download

A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.

There is a newer version: 5.2.4
Show newest version
/*
 * Copyright (C) 2017 HaiYang Li
 *
 * 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.
 */

package com.landawn.abacus.util;

import java.lang.reflect.ParameterizedType;

import com.landawn.abacus.type.Type;
import com.landawn.abacus.type.TypeFactory;

/**
 *
 *
 * Represents a generic type {@code T}. Java doesn't yet provide a way to
 * represent generic types, so this class does. Forces clients to create a
 * subclass of this class which enables retrieval the type information even at
 * runtime.
 *
 * 

For example, to create a type literal for {@code List}, you can * create an empty anonymous inner class: * *

 * TypeReference<List<String>> list = new TypeReference<List<String>>() {};
 * 
* This syntax cannot be used to create type literals that have wildcard * parameters, such as {@code Class} or {@code List}. * * @author Haiyang Li * @param * @since 0.9 */ public abstract class TypeReference { protected final Type type; protected TypeReference() { type = TypeFactory.getType(((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]); } /** * * * @return */ public Type type() { return type; } public abstract static class TypeToken extends TypeReference { } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy