java.lang.Class.getTypeName()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(329)

本文整理了Java中java.lang.Class.getTypeName()方法的一些代码示例,展示了Class.getTypeName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.getTypeName()方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:getTypeName

Class.getTypeName介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return the qualified name of the given class: usually simply
 * the class name, but component type class name + "[]" for arrays.
 * @param clazz the class
 * @return the qualified name of the class
 */
public static String getQualifiedName(Class<?> clazz) {
  Assert.notNull(clazz, "Class must not be null");
  return clazz.getTypeName();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Check whether the given class matches the user-specified type name.
 * @param clazz the class to check
 * @param typeName the type name to match
 */
public static boolean matchesTypeName(Class<?> clazz, @Nullable String typeName) {
  return (typeName != null &&
      (typeName.equals(clazz.getTypeName()) || typeName.equals(clazz.getSimpleName())));
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Return the qualified name of the given class: usually simply
 * the class name, but component type class name + "[]" for arrays.
 * @param clazz the class
 * @return the qualified name of the class
 */
public static String getQualifiedName(Class<?> clazz) {
  Assert.notNull(clazz, "Class must not be null");
  return clazz.getTypeName();
}

代码示例来源:origin: org.junit.jupiter/junit-jupiter-engine

/**
 * Properties {@link #annotationType} and {@link #reason} are <b>not</b>
 * included on purpose. This allows more cache hits when using instances
 * of this class as keys in a hash map.
 */
private int computeHashCode() {
  return Objects.hash(annotationType.getTypeName(), engine, source);
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Check whether the given class matches the user-specified type name.
 * @param clazz the class to check
 * @param typeName the type name to match
 */
public static boolean matchesTypeName(Class<?> clazz, @Nullable String typeName) {
  return (typeName != null &&
      (typeName.equals(clazz.getTypeName()) || typeName.equals(clazz.getSimpleName())));
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return a descriptive name for the given object's type: usually simply
 * the class name, but component type class name + "[]" for arrays,
 * and an appended list of implemented interfaces for JDK proxies.
 * @param value the value to introspect
 * @return the qualified name of the class
 */
@Nullable
public static String getDescriptiveType(@Nullable Object value) {
  if (value == null) {
    return null;
  }
  Class<?> clazz = value.getClass();
  if (Proxy.isProxyClass(clazz)) {
    StringBuilder result = new StringBuilder(clazz.getName());
    result.append(" implementing ");
    Class<?>[] ifcs = clazz.getInterfaces();
    for (int i = 0; i < ifcs.length; i++) {
      result.append(ifcs[i].getName());
      if (i < ifcs.length - 1) {
        result.append(',');
      }
    }
    return result.toString();
  }
  else {
    return clazz.getTypeName();
  }
}

代码示例来源:origin: apache/geode

private <T> T convertJdbcObjectToJavaType(Class<T> javaType, Object jdbcObject) {
 try {
  return javaType.cast(jdbcObject);
 } catch (ClassCastException classCastException) {
  throw JdbcConnectorException.createException("Could not convert "
    + jdbcObject.getClass().getTypeName() + " to " + javaType.getTypeName(),
    classCastException);
 }
}

代码示例来源:origin: MovingBlocks/Terasology

private static boolean hasSenderAnnotation(Method method) {
  final Class[] paramTypes = method.getParameterTypes();
  final Annotation[][] paramAnnotations = method.getParameterAnnotations();
  for (int i = 0; i < paramAnnotations.length; i++) {
    if (paramTypes[i].getTypeName().equals(ENTITY_REF_NAME)) {
      if (paramAnnotations[i].length == 0) {
        return false;
      } else {
        for (Annotation annotation: paramAnnotations[i]) {
          if (annotation instanceof Sender) {
            return true;
          }
        }
      }
    }
  }
  return true;
}

代码示例来源:origin: Graylog2/graylog2-server

private Object getProperty(Object bean, String fieldName) {
  try {
    Object property = PropertyUtils.getProperty(bean, fieldName);
    if (property == null) {
      // in case the bean is a Map, try again with a simple property, it might be masked by the Map
      property = PropertyUtils.getSimpleProperty(bean, fieldName);
    }
    log.debug("[field access] property {} of bean {}: {}", fieldName, bean.getClass().getTypeName(), property);
    return property;
  } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
    log.debug("Unable to read property {} from {}", fieldName, bean);
    return null;
  }
}

代码示例来源:origin: jersey/jersey

@Override
  public String getId() {
    return getBeanClass().getTypeName() + "#jersey";
  }
}

代码示例来源:origin: alibaba/Sentinel

private static void registerFallback() {
    // Register fallback handler for consumer.
    // If you only want to handle degrading, you need to
    // check the type of BlockException.
    DubboFallbackRegistry.setConsumerFallback((a, b, ex) ->
      new RpcResult("Error: " + ex.getClass().getTypeName()));
  }
}

代码示例来源:origin: konsoletyper/teavm

@Override
public boolean isApplicable(MethodReference methodReference) {
  return classSource.isSuperType(Resource.class.getTypeName(), methodReference.getClassName()).orElse(false);
}

代码示例来源:origin: konsoletyper/teavm

@Override
public boolean canHandle(MethodReference method) {
  return classSource.isSuperType(Resource.class.getTypeName(), method.getClassName()).orElse(false);
}

代码示例来源:origin: aol/micro-server

@Test
public void namingClasses() {
  System.out.println(ActiveEventsTest.class.getCanonicalName());
  System.out.println(ActiveEventsTest.class.getName());
  System.out.println(ActiveEventsTest.class.getSimpleName());
  System.out.println(ActiveEventsTest.class.getPackage()
                       .getName());
  System.out.println(ActiveEventsTest.class.getTypeName());
}

代码示例来源:origin: blox/blox

@Test
public void itDeserializesExceptionsWithOnlyMessageConstructor() {
 ObjectNode response =
   response(
     error(
       ThrowableSerializationMixin.ERROR_CODE,
       VALID_MESSAGE,
       data(RuntimeException.class.getTypeName())));
 Throwable throwable = resolver.resolveException(response);
 assertThat(throwable).isInstanceOf(RuntimeException.class).hasMessage(VALID_MESSAGE);
}

代码示例来源:origin: blox/blox

@Test
public void itPrefersMessageFromDataOverMessageFromError() {
 ObjectNode response =
   response(
     error(
       ThrowableSerializationMixin.ERROR_CODE,
       VALID_MESSAGE,
       data(RuntimeException.class.getTypeName(), "message=" + OTHER_MESSAGE)));
 Throwable throwable = resolver.resolveException(response);
 assertThat(throwable).isInstanceOf(RuntimeException.class).hasMessage(OTHER_MESSAGE);
}

代码示例来源:origin: blox/blox

@Test
public void itDeserializesPojoExceptionsWithJsonCreatorConstructor() {
 ObjectNode response =
   response(
     error(
       ThrowableSerializationMixin.ERROR_CODE,
       VALID_MESSAGE,
       data(PojoTestException.class.getTypeName(), "someValue=foo", "anotherValue=bar")));
 Throwable throwable = resolver.resolveException(response);
 assertThat(throwable)
   .isInstanceOf(PojoTestException.class)
   .hasMessage("foo:bar")
   .hasFieldOrPropertyWithValue("someValue", "foo")
   .hasFieldOrPropertyWithValue("anotherValue", "bar");
}

代码示例来源:origin: blox/blox

@Test
public void itReturnsNullForOtherErrorCodes() {
 ObjectNode response =
   response(
     error(RANDOM_ERROR_CODE, VALID_MESSAGE, data(PojoTestException.class.getTypeName())));
 Throwable throwable = resolver.resolveException(response);
 assertThat(throwable).isNull();
}

代码示例来源:origin: blox/blox

@Test
public void itReturnsNullWhenJacksonDeserializationFails() {
 ObjectNode response =
   response(
     error(
       ThrowableSerializationMixin.ERROR_CODE,
       VALID_MESSAGE,
       data(PojoTestException.class.getTypeName(), "invalidProperty=badValue")));
 Throwable throwable = resolver.resolveException(response);
 assertThat(throwable).isNull();
}

代码示例来源:origin: Alluxio/alluxio

@Test
public void getInStreamUfs() throws Exception {
 WorkerNetAddress worker1 = new WorkerNetAddress().setHost("worker1");
 WorkerNetAddress worker2 = new WorkerNetAddress().setHost("worker2");
 BlockInfo info = new BlockInfo().setBlockId(0);
 URIStatus dummyStatus =
   new URIStatus(new FileInfo().setPersisted(true).setBlockIds(Collections.singletonList(0L))
     .setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
 OpenFilePOptions readOptions = OpenFilePOptions.newBuilder()
   .setFileReadLocationPolicy(MockFileWriteLocationPolicy.class.getTypeName()).build();
 InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, sConf);
 ((MockFileWriteLocationPolicy) options.getUfsReadLocationPolicy())
   .setHosts(Arrays.asList(worker1, worker2));
 when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo());
 when(mMasterClient.getWorkerInfoList()).thenReturn(
   Arrays.asList(new WorkerInfo().setAddress(worker1), new WorkerInfo().setAddress(worker2)));
 // Location policy chooses worker1 first.
 assertEquals(worker1, mBlockStore.getInStream(BLOCK_ID, options).getAddress());
 // Location policy chooses worker2 second.
 assertEquals(worker2, mBlockStore.getInStream(BLOCK_ID, options).getAddress());
}

相关文章

Class类方法