rethc's Profile
Reputation: 12
Tradesman
- Group:
- Active Members
- Active Posts:
- 76 (0.19 per day)
- Joined:
- 23-April 12
- Profile Views:
- 636
- Last Active:
Mar 31 2013 12:22 AM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
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? -
In Topic: Reflection to store a java file from a class
Posted 28 Mar 2013
thanks -
In Topic: While Loop and Cout Statements
Posted 1 Nov 2012
int atoi(temp[i]);
temp[i] is a single character. Just use temp, as it is an array of characters
int v = atoi(temp);
-
In Topic: Question on pointers and arrays
Posted 29 Oct 2012
I want to know if this is possible aswell. Would this code work?
#include <iostream> using namespace std; int main() { int *testArray; for(int i = 0; i < 3; i++) { cin >> *(testArray = new int()); } cout << endl << "Array output: " << endl; cout << *(testArray - 32) << endl; cout << *(testArray - 4) << endl; cout << *testArray << endl; return 0; }
Edit: sorry for the thread hijack, i didn't want to post another thread about the same thing. -
In Topic: What are the 3 types of strings in C++?
Posted 27 Oct 2012
aresh, on 27 October 2012 - 06:48 AM, said:Maybe the examiner means string literal? 'Coz they are the only two types I know of
Thanks, i think that may be it.
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.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
rethc has no profile comments yet. Why not say hello?