rethc's Profile User Rating: -----

Reputation: 12 Tradesman
Group:
Active Members
Active Posts:
76 (0.08 per day)
Joined:
23-April 12
Profile Views:
1,086
Last Active:
User is offline Mar 31 2013 12:22 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   rethc has not set their status

Posts I've Made

  1. In Topic: Reflection to store a java file from a class

    Posted 30 Mar 2013

    Here is my reflection class code:
    try
    		{			
    			Class c = Class.forName(className);
    			Method methods[] = c.getDeclaredMethods();
    			int modifiers = c.getModifiers();
    			Constructor constructor[] = c.getConstructors();
    			Class inteface[] = c.getInterfaces();
    			Class superclass = c.getSuperclass();
    			Field field[] = c.getDeclaredFields();
    			
    
    			if(Modifier.isPublic(modifiers))
    			{
    				System.out.print("public ");
    			}
    			else if(Modifier.isPrivate(modifiers))
    			{
    				System.out.print("private ");
    			}
    			System.out.print(c.getName());		
    			System.out.print(" ");
    			System.out.print(superclass);
    			System.out.print(" ");
    			
    			for(int i = 0; i < field.length; i++)
    			{
    				System.out.print(inteface[i]);
    			}
    			System.out.println("");	
    			for(int i = 0; i < field.length; i++)
    			{
    				System.out.println(field[i]);
    			}
    			for (int i = 0; i < constructor.length; i++)
    			{
    				System.out.println( constructor[i]);
    			}
    			for(int i = 0; i < methods.length; i++)
    			{
    				System.out.println(methods[i]);
    			}
    		}
    		catch(Exception e)
            {
                e.printStackTrace();
            }
    


    Here is my code for the class i want to use reflection on:
    public class Cat extends Animal implements Behaviour 
    {
    	private Barn barn;
    	public Cat(String name, int age, Barn barn) 
    	{
    		super(name, age);
    		this.barn = barn;
    	}	
    }
    	public void run() {}
    	public void eat() {}
    }
    
    


    The reflection code I have posted above returns the following:
    public Cat class Animal interface Behaviour
    private Barn Cat.barn
    public Cat(java.lang.String,int,Barn)
    public void Cat.eat()
    public void Cat.run()
    
    


    For my assignment i need to make it exactly like the source code without the bodies. How do i get the parameter variable names in the constructor using reflection?
  2. In Topic: Reflection to store a java file from a class

    Posted 28 Mar 2013

    thanks

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

rethc hasn't added any friends yet.

Comments

rethc has no profile comments yet. Why not say hello?