Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a Convenience Method in Java? [closed]

Tags:

java

android

I am told that the Activity.findViewById(int) method is a convenience method that calls View.findViewById(int) behind the scenes.

I am unable to find any documentation for explaining convenience methods wrt Java (I can see only iOS).

PS : I am unable to find any answer during my cursory Google search or via SO prev posts.If there is already one do point out so that I will close this one.

like image 979
UnderDog Avatar asked Sep 28 '13 05:09

UnderDog


People also ask

What is a convenience method?

convenience method (plural convenience methods) (object-oriented programming) A method created for convenience so that some other, more complex task can be solved more easily.

What is a convenience class Java?

A "convenience method" or "convenience class" generally means a class that doesn't do anything itself, but provides simplified access to other classes or groups of classes. For example, the "random()" method in java. lang. Math is a convenience method that provides a simple way to use the more powerful java.


1 Answers

A convenience method, in any language which has a concept of methods, is just that. A method that makes things more convenient.

This usually means taking something that is complex or verbose, and making it more accessible. Examples include pretty much everything in helper classes like Collections or Arrays. As well as factory methods (to a certain extent, there are reasons for factories beyond simple convenience).

For a more formal definition from Wikipedia (http://en.wikipedia.org/wiki/Convenience_function):

A convenience function is a non-essential subroutine in a programming library or framework which is intended to ease commonly performed tasks.

like image 137
Aurand Avatar answered Oct 12 '22 20:10

Aurand