Java中的类类型 – Spring MongoDB源代码

huangapple go评论85阅读模式
英文:

Class type in java -spring mongodb source code

问题

我正在查看Spring-MongoDB项目的源代码。在这里https://github.com/spring-projects/spring-data-mongodb/blob/main/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/TypedAggregation.java

我发现了一个名为Class的类型,如下所示:

private final Class inputType;

我对这个Class类型感到好奇,我查找了Java中是否有任何与Type Class相关的关键字,但我没有找到任何信息。然后我在包中查找是否有一个名为Class的接口或类

Class

但我也没有找到任何信息。这些是我所能做的唯一可能性假设。有人可以解释一下这里的Class是什么吗?

英文:

I was going through the source code of Spring-MongoDB project. Here <https://github.com/spring-projects/spring-data-mongodb/blob/main/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/TypedAggregation.java>

I found a Type called Class like below

private final Class&lt;I&gt; inputType;

I became curious as to what is this Class type , I looked up if there is any keyword of java which pertains to any Type Class, I haven't found any, Then I looked upon in the package if there is a Interface or Class of with name

> Class

But I haven't found any, Those are the only possibilities of my set of assumptions I can make. Can someone help with what is Class here?

答案1

得分: 1

Class 类指的是 Java 类在运行时的表示。它是 Java 反射 API 的基本组成部分,允许你在运行时动态地检查和与类和对象的结构和行为交互。

Class 类是 java.lang 包的一部分,它本身也是一个类。它提供了各种方法,允许你访问有关类的信息,如类的名称、修饰符、字段、方法、构造函数、超类、接口、注解等。

例如:

Class&lt;String&gt; clazz = String.class;
System.out.println(clazz.getName());       // 输出:java.lang.String
System.out.println(clazz.getSimpleName()); // 输出:String

查看以下链接以获取更多信息:

英文:

The class Class refers to the representation of a Java class at runtime. It is a fundamental part of the Java reflection API, which allows you to examine and interact with the structure and behavior of classes and objects dynamically, at runtime.

The class Class is part of the java.lang package and is itself a class. It provides various methods that allow you to access information about a class, such as its name, modifiers, fields, methods, constructors, superclasses, interfaces, annotations, etc.

For example:

Class&lt;String&gt; clazz = String.class;
System.out.println(clazz.getName());       // Output: java.lang.String
System.out.println(clazz.getSimpleName()); // Output: String

Check this out:

huangapple
  • 本文由 发表于 2023年7月28日 00:06:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76781585.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定