324-lecture8 - CSC324 Principles of Programming Languages...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC324: Principles of Programming Languages Lecture 8 University of Toronto 0 Java’s Reflection Wael Aboulsaadat
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CSC324: Principles of Programming Languages Internal Representation of .class (Java’s bytecode) public class Point { public Point(int x, int y) { x = 5; Y = 10; } 5 x object University of Toronto public int getX() { return x; } public int getY() { return y; } protected int x, y; } 3 {} {} {} Point(int,int) getX() getY() y class
Image of page 2
CSC324: Principles of Programming Languages The class Class square6 Instances of the class Class store information about classes uni0336 Class name uni0336 Inheritance uni0336 University of Toronto Interfaces implemented uni0336 Methods, members, etc. square6 Can look up instances: uni0336 By name uni0336 From an object
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CSC324: Principles of Programming Languages Discovering the type of a Class University of Toronto
Image of page 4
CSC324: Principles of Programming Languages Discovering the Methods of a class University of Toronto
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CSC324: Principles of Programming Languages Calling a Method using Reflection 1. Look up a method based on its signature: the name and list of parameter types 2. Specify signature as a comma-separated list of Class objects uni0336 Specifies the types of arguments University of Toronto uni0336 Special values for types like int and boolean 3. Call the method, passing in parameters and capturing return value
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern