Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: What is the function of this statement?

  1. #1
    Junior Member
    Join Date
    Dec 2021
    Thanked 0 Times in 0 Posts

    Default What is the function of this statement?

    Without the new keyword, I assume it's not creating an object.

    Is it just referencing whatever the Thread.currentThread() is?

    Would it be fair to say that this statement is just pulling a reference of the object into the method so that the method perform operations on it?

    Thread t = Thread.currentThread();

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,662 Times in 2,612 Posts

    Default Re: What is the function of this statement?

    Did you have any questions about what the API doc says?
    Find the API doc here: https://docs.oracle.com/javase/8/docs/api/index.html

    That statements assigns the value returned by the currentThread method to the variable: t.
    t can then be used to call the methods for the current Thread.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. What is the function of the string in this statement?
    By FightingIrishman in forum Java Theory & Questions
    Replies: 4
    Last Post: January 15th, 2022, 10:36 AM
  2. Replies: 2
    Last Post: December 10th, 2019, 06:17 AM
  3. How to turn my If statement into a case/switch statement?
    By blobby404 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: June 19th, 2014, 03:11 PM
  4. [SOLVED] A Loop statement and a switch statement issue
    By sternfox in forum Loops & Control Statements
    Replies: 13
    Last Post: March 7th, 2013, 04:19 PM
  5. Replacing an If statement with a Switch statement
    By logi in forum Loops & Control Statements
    Replies: 9
    Last Post: February 4th, 2013, 12:21 AM