Last active
April 27, 2020 11:40
-
-
Save shelajev/6a0502b68b62fcf194c072c7cc002cee to your computer and use it in GitHub Desktop.
Reflection examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import javafx.application.Application; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.stage.Stage; | |
import java.lang.reflect.Method; | |
public class Sensitive extends Application { | |
@Override | |
public void start(Stage stage) { | |
Button btn = new Button("It worked on your machine. Interesting..."); | |
Scene scene = new Scene(btn, 400, 300); | |
stage.setTitle("JavaFX is on the classpath."); | |
stage.setScene(scene); | |
stage.show(); | |
} | |
public static void main(String[] args) throws Throwable { | |
Class<?> applicationClass = Class.forName("javafx.application.Application"); | |
Method launch = applicationClass.getDeclaredMethod("launch", Class.class, String[].class); | |
launch.invoke(null, Sensitive.class, args); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.reflect.Method; | |
import java.util.Arrays; | |
public class Sort { | |
public static void main(String[] args) throws Throwable{ | |
int[] n = {3, 1, 4, 1, 5, 9, 2, 6}; | |
Method sort = Arrays.class.getDeclaredMethod("sоrt", int[].class); | |
sort.invoke(null, n); | |
System.out.println(Arrays.toString(n)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment