StackTraceElement.isNativeMethod() Method

Advertisements


Description

The java.lang.StackTraceElement.isNativeMethod() method returns true if the method containing the execution point represented by this stack trace element is a native method.

Declaration

Following is the declaration for java.lang.StackTraceElement.isNativeMethod() method

public boolean isNativeMethod()

Parameters

  • NA

Return Value

This method returns true if the method containing the execution point represented by this stack trace element is a native method.

Exception

  • NA

Example

The following example shows the usage of java.lang.StackTraceElement.isNativeMethod() method.

package com.tutorialspoint;

import java.lang.*;

public class StackTraceElementDemo {

   public static void main(String[] args) {

      function1();
   }
 
   public static void function1()
   {
      new StackTraceElementDemo().function2();
   }
 
   public void function2() 
   {
      int i;  
      System.out.println("Is Native method ? :");
    
      // print stack trace
      for(i = 1 ; i < 3 ; i++ ) {
         System.out.println(Thread.currentThread().getStackTrace()[i].
         isNativeMethod());
      }
   }
}  

Let us compile and run the above program, this will produce the following result:

Is Native method ? :
false
false



Advertisements
Advertisements