Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4016180
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:42:31+00:00 2026-05-20T09:42:31+00:00

I am beginner with Java, and I would like to write some code like

  • 0

I am beginner with Java, and I would like to write some code like this :

TEST(myfunction(1, 2, 3));

Where TEST is :

  • Either a macro as used in C
  • Either a function which need the address of the function myfunction

In my code, I would like TEST to do some code :

TEST(function) {
    if (function()) 
        // code
    else
        //code
}

I know pointers are not usable in Java.
An idea to help me ?

[EDIT]
Here is another example :

TEST(myfunction(1, 2, 3));

Where TEST is implemented :

void TEST (function(args[])) {
try {
    function();
}
catch (Exception e) {
    // Exception happened !
}

}

Thanks to that, with only one code line, I will be able to use try catch !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:42:32+00:00Added an answer on May 20, 2026 at 9:42 am

    Java doesn’t have pointers to functions. The typical way functions are passed around in Java is to pass an object that implements Runnable.

    EDIT: I’ve revised my example to be closer to your second case.

    In your case, where you want a boolean return value, you can define your own interface:

    public interface BooleanTest {
        boolean test(Object... args) throws Exception;
    }
    

    and then later:

    class MyTest implements BooleanTest {
        private boolean result;
        public MyTest(int a, int b, int c) {
            result = a + b == c;
        }
        // stupid test -- don't _have_ to declare "throws Exception"
        public boolean test(Object... args) {
            return result && args.length == 3;
        }
    }
    
    TEST(new MyTest(1, 2, 3));
    

    and inside TEST:

    TEST(BooleanTest test) {
        try {
            if (test.test("Jack", "and", "Jill")) {
                // ...
            }
        } catch (Exception e) {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam a Java beginner and i would like to ask whats the pros and
I'm a beginner in Java programming and would like to understand what is the
I'm quite a beginner with java and Android in general so I would like
As a (pedantic) beginner Java programmer I would like to know, is it a
I am currently switching languages from Java(beginner) to c++ and would like to replicate
I am a Java beginner and I would appreciate it if someone here can
I'm a beginner in Java, I used PHP, C++ and Lua and never had
I'm totally beginner in java. In javascript i have this regex: /[^0-9.,\-\ ]/gi How
I'm a pretty big noob to Java, but I would like try out htmlunit.
This is a real beginner question (I'm still learning the Java basics). I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.