java.beans.BeanInfo.getPropertyDescriptors()の使い方

サンプルコード

package com.arkgame.study;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.List;

import com.arkgame.study.MainDemo.InfoArrayClass;

public class PropertyDescriptorsDemo {

	public static void main(String[] args) throws IntrospectionException {
		BeanInfo info = Introspector.getBeanInfo(InfoArrayClass.class);
		PropertyDescriptor[] descriptors = info.getPropertyDescriptors();
		System.out.println("実行結果");
		for (int i = 0; i < descriptors.length; i++) {
			System.out.println(descriptors[i].getClass().getName() + ":" + descriptors[i].getName());
		}

	}

	public class InfoIndexedListClass {
		private List<String> infoIndexedListClass = new ArrayList<String>();

		public String getInfoIndexedListClass(int index) {
			return infoIndexedListClass.get(index);
		}

		public void setInfoIndexedListClass(int index, String element) {
			this.infoIndexedListClass.set(index, element);
		}

		public List<String> getInfoIndexedListClass() {
			return infoIndexedListClass;
		}

		public void setInfoIndexedListClass(List<String> InfoIndexedListClass) {
			this.infoIndexedListClass = InfoIndexedListClass;
		}

	}
}

実行結果
java.beans.PropertyDescriptor:class
java.beans.PropertyDescriptor:infoArrayClass

Java

Posted by arkgame