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

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

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

Class.getName介绍

[英]Returns the name of the class represented by this Class. For a description of the format which is used, see the class definition of Class.
[中]返回此类表示的类的名称。有关所使用格式的说明,请参见类的类定义。

代码示例

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

@Override
  public String toString() {
    return (String.class.getName() + " -> @" + this.annotationType.getName() + " " +
        this.fieldType.getName() + ": " + this.annotationFormatterFactory);
  }
}

代码示例来源:origin: stackoverflow.com

private boolean isMyServiceRunning(Class<?> serviceClass) {
  ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
  for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
    if (serviceClass.getName().equals(service.service.getClassName())) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: google/guava

/**
 * Returns human readable string representation of {@code type}.
 *
 * <p>The format is subject to change.
 */
static String toString(Type type) {
 return (type instanceof Class) ? ((Class<?>) type).getName() : type.toString();
}

代码示例来源:origin: square/retrofit

@Override public String toString() {
  return String.format("%s.%s() %s",
    method.getDeclaringClass().getName(), method.getName(), arguments);
 }
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public String toString() {
    return clazz.getName() + " " + name;
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public String toString() {
    return clazz.getName() + " " + name;
  }
}

代码示例来源:origin: google/guava

/**
 * Returns the package name of {@code clazz} according to the Java Language Specification (section
 * 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without
 * attempting to define the {@link Package} and hence load files.
 */
public static String getPackageName(Class<?> clazz) {
 return getPackageName(clazz.getName());
}

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

@SuppressWarnings("unchecked")
static Class<? extends Annotation> getAnnotationType(AnnotationFormatterFactory<? extends Annotation> factory) {
  Class<? extends Annotation> annotationType = (Class<? extends Annotation>)
      GenericTypeResolver.resolveTypeArgument(factory.getClass(), AnnotationFormatterFactory.class);
  if (annotationType == null) {
    throw new IllegalArgumentException("Unable to extract parameterized Annotation type argument from " +
        "AnnotationFormatterFactory [" + factory.getClass().getName() +
        "]; does the factory parameterize the <A extends Annotation> generic type?");
  }
  return annotationType;
}

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

@Override
public void destroy() {
  if (this.loadTimeWeaver instanceof InstrumentationLoadTimeWeaver) {
    if (logger.isDebugEnabled()) {
      logger.debug("Removing all registered transformers for class loader: " +
          this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
    }
    ((InstrumentationLoadTimeWeaver) this.loadTimeWeaver).removeTransformers();
  }
}

代码示例来源:origin: google/guava

@Override
 public boolean apply(StackTraceElement element) {
  return element.getClassName().equals(clazz.getName());
 }
};

代码示例来源:origin: ReactiveX/RxJava

/**
   * Report a ProtocolViolationException with a personalized message referencing
   * the simple type name of the consumer class and report it via
   * RxJavaPlugins.onError.
   * @param consumer the class of the consumer
   */
  public static void reportDoubleSubscription(Class<?> consumer) {
    RxJavaPlugins.onError(new ProtocolViolationException(composeMessage(consumer.getName())));
  }
}

代码示例来源:origin: google/guava

private void runTestMethod(ClassLoader classLoader) throws Exception {
 Class<?> test = classLoader.loadClass(FuturesTest.class.getName());
 Object testInstance = test.newInstance();
 test.getMethod("setUp").invoke(testInstance);
 test.getMethod(getName()).invoke(testInstance);
 test.getMethod("tearDown").invoke(testInstance);
}

代码示例来源:origin: google/guava

private void checkHelperVersion(ClassLoader classLoader, String expectedHelperClassName)
  throws Exception {
 // Make sure we are actually running with the expected helper implementation
 Class<?> abstractFutureClass = classLoader.loadClass(AbstractFuture.class.getName());
 Field helperField = abstractFutureClass.getDeclaredField("ATOMIC_HELPER");
 helperField.setAccessible(true);
 assertEquals(expectedHelperClassName, helperField.get(null).getClass().getSimpleName());
}

代码示例来源:origin: google/guava

private void checkHelperVersion(ClassLoader classLoader, String expectedHelperClassName)
  throws Exception {
 // Make sure we are actually running with the expected helper implementation
 Class<?> abstractFutureClass = classLoader.loadClass(AggregateFutureState.class.getName());
 Field helperField = abstractFutureClass.getDeclaredField("ATOMIC_HELPER");
 helperField.setAccessible(true);
 assertEquals(expectedHelperClassName, helperField.get(null).getClass().getSimpleName());
}

代码示例来源:origin: google/guava

private static ResourceInfo resourceInfo(Class<?> cls) {
 String resource = cls.getName().replace('.', '/') + ".class";
 ClassLoader loader = cls.getClassLoader();
 return ResourceInfo.of(resource, loader);
}

代码示例来源:origin: google/guava

private static ClassPath.ClassInfo findClass(
  Iterable<ClassPath.ClassInfo> classes, Class<?> cls) {
 for (ClassPath.ClassInfo classInfo : classes) {
  if (classInfo.getName().equals(cls.getName())) {
   return classInfo;
  }
 }
 throw new AssertionError("failed to find " + cls);
}

代码示例来源:origin: google/guava

private void checkStackTrace(ExecutionException e) {
 // Our call site for get() should be in the trace.
 int index = findStackFrame(e, getClass().getName(), "getExpectingExecutionException");
 assertThat(index).isNotEqualTo(0);
 // Above our method should be the call to get(). Don't assert on the class
 // because it could be some superclass.
 assertThat(e.getStackTrace()[index - 1].getMethodName()).isEqualTo("get");
}

代码示例来源:origin: google/guava

public void testToString() {
 assertEquals(int[].class.getName(), Types.toString(int[].class));
 assertEquals(int[][].class.getName(), Types.toString(int[][].class));
 assertEquals(String[].class.getName(), Types.toString(String[].class));
 Type elementType = List.class.getTypeParameters()[0];
 assertEquals(elementType.toString(), Types.toString(elementType));
}

代码示例来源:origin: google/guava

public <T> void testToString() {
 assertEquals(String.class.getName(), new TypeToken<String>() {}.toString());
 assertEquals("T", TypeToken.of(new TypeCapture<T>() {}.capture()).toString());
 assertEquals("java.lang.String", new Entry<String, Integer>() {}.keyType().toString());
}

代码示例来源:origin: google/guava

public void testGetPackageName() throws Exception {
 assertEquals("java.lang", Reflection.getPackageName(Iterable.class));
 assertEquals("java", Reflection.getPackageName("java.MyType"));
 assertEquals("java.lang", Reflection.getPackageName(Iterable.class.getName()));
 assertEquals("", Reflection.getPackageName("NoPackage"));
 assertEquals("java.util", Reflection.getPackageName(Map.Entry.class));
}

相关文章

Class类方法