AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Java for loop syntax colon1/19/2024 ![]() ![]() That's all about the double colon operator of Java 8. If you want to learn more, then these Java collections and Stream courses are the best places to start with. Remember, there is no parenthesis when you refer to a method using method reference or lambda expression in Java 8. The idea is that if you are passing a lambda expression, like a function that takes a value and prints in the console then instead of giving lambda expression, just pass the println() method of PrintStream class which you can access as a System.out::println. An array constructor reference (TypeName::new) like String::new.A class constructor reference (ClassName::new) like ArrayList::new.An instance method of an arbitrary object of a particular type ( ClassName::methodName).A super method of a particular object ( super::methodName).An instance method of a particular object (instanceRef::methodName) like System.out::println.A static method (ClassName::methodName) like Person::getAge.Here are some examples of a method reference in Java 8: You can use the double colon operator (::) wherever you need to use the method reference. Where can you use the double colon operator in Java? For referring to a static method, you can either use className or instanceRef, but to refer to an instance method of a particular object, you need to use instanceRef. ![]() You can use method reference or double colon operator to refer to a static method, an instance method, or a constructor. ![]()
0 Comments
Read More
Leave a Reply. |