Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Correct approach to compare `ResolvedType` with a raw `Class<?>`?

Abierto
#72 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
20/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
java
Área
tooling

Línea de trabajo

Empieza por las API ResolvedType y TypeResolver mencionadas en el issue, especialmente resolve, getTypeParameters, getErasedType y equals. Reproduce el ejemplo de GenericType y compara los enfoques raw-Class y resolved-type; el resultado debe ser una recomendación clara para comprobar si el resolved type es String, incluido cualquier overhead relevante.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

What's the appropriate way to see if a ResolvedType represents a simple class that I know about?

Let's say I pass a new GenericType<String>{} to a method, and I just want to see if the generic parameter is String. I think (I haven't tried it yet) I would do this (code not optimized, for illustration):

void foo(GenericType<?> genericType) {
  TypeResolver typeResolver = new TypeResolver();
  ResolvedType resolvedType = typeResolver.resolve(genericType);

How would I then see if resolvedType indicates a simple String? I'm guessing I could do this:

    if(resolvedType.getTypeParameters.isEmpty() && resolvedType.getErasedType().equals(String.class)) {
      …

But that seems sort of awkward. Is there a better way?

(Note that the resolvedType.getTypeParameters.isEmpty() check is arguably not necessary here, as String has no generic parameters, but I'm looking for a general approach.)

Or should I be going in the other direction, resolving String.class and then comparing the resolved types?

    if(resolvedType.equals(typeResolver.resolve(String.class))) {
      …

I don't know how much overhead the extra resolution of String.class adds, though.

This may be related to #31.

Lenguaje dominante
Java
Estrellas
266
Forks
47
Merge medio
1 h 42 min
PR fusionados (30 d)
1

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de FasterXML/java-classmate

Todos los issues de FasterXML/java-classmate

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.