See if field exists in class

后端 未结 6 1807
眼角桃花
眼角桃花 2021-02-03 21:47

I have a class with various variables

public class myClass{

    public int id;
    public String category;
    public String description;
    public String star         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-03 22:33

    As others already mentioned reflection is what you need.

    If you need to access a private field you can use Class.getDeclaredField(String name)

提交回复
热议问题