THINK in Patten Of Java

xiaoxiao2021-03-06  64

I have sent this in the forum, but I didn't answer. Wrap here: Think in Partten of Java, About Dynamic Proxies, there is such exercises: Exercise: Use the java dynamic proxy to create an Object That ACTS AS A Front End for a Simple Configuration File. For Example , in good_stuff.txt you can have entries like this: a = 1b = 2c = "Hello World"

A Client Programmer of this NeatPropertyBundle Could The Write:

NEATPROPERTYBUNDLE P = New NeatPropertyBundle ("Good_stuff");

System.out.println (p.a); system.out.println (p.b); system.out.println (p.c);

The contents of the configuration file can contain anything, with any variable names. The dynamic proxy will either map to the name or tell you it does not exist somehow (probably by returning null). If you set a property and it does not Already Exist, The Dynamic Proxy Will Create The New Entry. The Tostring () Method Should Display All The Current Entries.

I originally thought this: import java.lang.Reflect. *; Import java.io. *;

class NeatPropertyBundle extends Proxy {NeatPropertyBundle (final String textFileName) {super (new InvocationHandler () {public Object invoke (Object proxy, Method method, Object [] args) {BufferedReader br = new BufferedReader (new FileReader (textFileName)); .. .... / * Here you get the field name you want to read through Method.getName, then read it in the configuration file. * /}});}} But I found that the topic is required to take any member variables to the NeatPropertyBundle object. , Not the method. The variable name is also arbitrary, how should this be implemented? --------------------------------------- The discussion on the forum is that this is the wrong question. See what opinions in everyone.

转载请注明原文地址:https://www.9cbs.com/read-88404.html

New Post(0)