Profesionāls interneta atkarīgais • Spēļu entuziasts • Tehnoloģiju radītājs
Profesionāls interneta atkarīgais • Spēļu entuziasts • Tehnoloģiju radītājs

Kā Java valodā noteikt, kura metode izsauca konkrēto metodi

Kā noskaidrot, kura Java metode izsauca citu metodi!
Šo lapu no angļu valodas jūsu ērtībām ir tulkojuši mani augsti motivētie mākslīgā intelekta praktikanti. Viņi joprojām mācās, tāpēc dažas kļūdas varētu būt paslīdējušas garām. Lai iegūtu visprecīzāko informāciju, lūdzu, skatiet angļu valodas versiju.
Sākums Emuārs Kā Java valodā noteikt, kura metode izsauca konkrēto metodi

Ņem vērā, ka šis raksts ir no 2010. gada oktobra — dažas detaļas var būt vecākas, bet lasīt joprojām interesanti!

    In some situations it could be handy to figure out who called a specific method at runtime, especially when a specific method is used by hundreds of methods and you have no clue how to recreate the execution.
    This can either be done by using external Java profilers which reads and analyze a Java applications memory usage or you can get the caller method programmatically within the application at runtime.
    This is done by basically instantly dumping a stack trace without throwing an Exception. However dumping the stack trace (with or without creating an Exception) has a huge performance cost and should really only be done at temporarily special circumstances.
    If you would like to get the stack traces of all active threads you can use:
    If you only need the stack trace for the current thread you can use:
    To get the calling method you can create a fancy method like:
    private static String getCallingMethodName() { StackTraceElement stack = Thread.currentThread().getStackTrace()[3]; return stack.getClassName() + "." + stack.getMethodName(); }

    Autors Special Agent Squeaky. Pirmo reizi publicēts 2010. gada 10. oktobrī. Pēdējo reizi atjaunināts 2010. gada 10. oktobrī.

    📺 Skaties Squeaky jaunāko video!

    Kā pievienot vienkāršus reāllaika subtitrus jūsu tiešraidei.