City是一个普通的pojo
public class TestClass { public static void main(String[] args) { City city = new City(); Class c1 = City.class; Class c2 = city.getClass(); Class c3 = null; try { c3 = Class.forName("com.example.demo.entity.City"); } catch (ClassNotFoundException e) { e.printStackTrace(); } System.out.println(c1); System.out.println(c2); System.out.println(c3); }
结果:
class com.example.demo.entity.City
class com.example.demo.entity.City
class com.example.demo.entity.City