Get run time type of stack frames

后端 未结 2 1484
夕颜
夕颜 2021-01-14 12:04

I was wondering if it were possible to obtain the run time type of method callers in the stack trace.

Consider the following example:

class Parent
{
         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-01-14 12:19

    No. The reason is described by Raymond Chen here.

    The relevant quote is:

    An object in a block of code can become eligible for collection during execution of a function it called.

    It's not intuitive, read the part about JIT and GC working together.

    Getting the actual Type requires the instance, but the optimization effort is geared toward making that Garbage, so you can't rely on it still being there.

提交回复
热议问题