---
title: "java"
author: "Sweblish"
date: "2011-09-15T20:56:30Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2011-09-15T20:56:30Z"
id: 1172902
url: "https://sweblish.iteye.com/blog/1172902"
---

这里做个使用记录
Student s = new Student();
String methodName = "getName";//这个在Student类中有该方法
Method method = s.getClass().getMethod(methodName);//内存中获取该方法
String res = (String)method.invoke(s);//这个是说s对象中的getName()方法没有参数,得到返回类型为String的结果。
//String res = (String)method.invoke(s,args);//这个是说s对象中的getName()方法有参数args,具体是什么类型的，自己指定一下就可以了，得到返回类型为String的结果。java编写底层数据时，反射是最常用的方法之一。