Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level09.lesson02.task02;
- /* И снова StackTrace
- Написать пять методов, которые вызывают друг друга.
- Каждый метод должен возвращать имя метода, вызвавшего его, полученное с помощью StackTrace.
- */
- public class Solution
- {
- public static void main(String[] args) throws Exception
- {
- method1();
- }
- public static String method1()
- {
- method2();
- //Напишите тут ваш код
- //System.out.println(Thread.currentThread().getStackTrace()[2].getMethodName());
- return Thread.currentThread().getStackTrace()[2].getMethodName();
- }
- public static String method2()
- {
- method3();
- //Напишите тут ваш код
- //System.out.println(Thread.currentThread().getStackTrace()[2].getMethodName());
- return Thread.currentThread().getStackTrace()[2].getMethodName();
- }
- public static String method3()
- {
- method4();
- //Напишите тут ваш код
- //System.out.println(Thread.currentThread().getStackTrace()[2].getMethodName());
- return Thread.currentThread().getStackTrace()[2].getMethodName();
- }
- public static String method4()
- {
- method5();
- //Напишите тут ваш код
- //System.out.println(Thread.currentThread().getStackTrace()[2].getMethodName());
- return Thread.currentThread().getStackTrace()[2].getMethodName();
- }
- public static String method5()
- {
- //Напишите тут ваш код
- //System.out.println(Thread.currentThread().getStackTrace()[2].getMethodName());
- return Thread.currentThread().getStackTrace()[2].getMethodName();
- }
- }
- /*
- [0] - это getStackTrace();
- [1] - это метод В КОТОРОМ вызван getMethodName();
- [2] - это метод ИЗ КОТОРОГО вызван метод В КОТОРОМ вызван getMethodName();
- */
Advertisement
Add Comment
Please, Sign In to add comment