CSC/ECE 517 Summer 2008/wiki1 3 jb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 40: Line 40:
==Java Reflection Links==
==Java Reflection Links==
[http://java.sun.com/docs/books/tutorial/reflect/index.html Pros and cons of reflection, written for Java but pretty generic]<br>
[http://java.sun.com/docs/books/tutorial/reflect/index.html Pros and cons of reflection, written for Java but pretty generic]<br>
[http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html Using Java reflection<br>
[http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html Using Java reflection]<br>
[http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/package-summary.html java.lang.reflect package documentation]<br>
[http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/package-summary.html java.lang.reflect package documentation]<br>


==Ruby Reflection Links==
==Ruby Reflection Links==
http://phrogz.net/programmingruby/ospace.html
http://phrogz.net/programmingruby/ospace.html

Revision as of 22:00, 1 June 2008

This wiki will explore how reflection is implemented with both Ruby and Java, with the goal of showing which language's implementation makes it easier to write, easier to understand, and more efficient.

Basics

Reflection in Java

class MountainBike
{
	boolean diskBrakes() { return true; }
	boolean knobbyTires() { return true; }

	public static void main (String argv[])
	{
		Class c = MountainBike.class;
		Method methods[] = c.getDeclaredMethods();
		for (int i=0; i<methods.length; i++)
		{
			System.out.println(methods[i].getName());
		}
	}
}

Reflection in Ruby

class MountainBike
  def diskBrakes 
      return true
  end
  def knobbyTires
      return true
    end
end

mb =  MountainBike.new
puts MountainBike.public_instance_methods(false)

Java Reflection Links

Pros and cons of reflection, written for Java but pretty generic
Using Java reflection
java.lang.reflect package documentation

Ruby Reflection Links

http://phrogz.net/programmingruby/ospace.html