What is the difference between getName(), getCanonicalName() and getSimpleName() in Java?
Hello! I just started learning reflection in Java and came across three methods: `getName()`, `getCanonicalName()` and `getSimpleName()`. I don't quite understand how they differ.
For example, I have a simple class `Person` in the package `com.example.model`. I tried writing this code:
```java
package com.example.model;
public class Person {
public static void main(String[] args) {
Class> clazz = Person.class;
System.out.println("getName: " + clazz.getName());
System.out.println("getSimpleName: " + clazz.getSimpleName());
System.out.println("getCanonicalName: " + clazz.getCanonicalName());
}
}
```
All three methods output something similar: `getName` shows `com.example.model.Person`, `getSimpleName` — just `Person`, and `getCanonicalNa
No answers yet.
Log in to leave an answer
Blogs
C++ for Machine Learning: Capabilities and Limitations