Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best practice to export function objects in Java?

Tags:

java

What is the best practice of creating function objects(a stateless object that exports a single method which works on other objects ) in Java ?

like image 498
Geek Avatar asked Feb 25 '13 13:02

Geek


People also ask

What is export function JavaScript?

The export statement is used when creating JavaScript modules to export objects, functions, variables from the module so they can be used by other programs with the help of the import statements. There are two types of exports. One is Named Exports and other is Default Exports.

How do I export multiple functions?

To export multiple functions in JavaScript, use the export statement and export the functions as an object. Alternatively, you can use the export statement in front of the function definitions. This exports the function in question automatically and you do not need to use the export statement separately.

How do I export functions in TypeScript?

Use named exports to export a function in TypeScript, e.g. export function sum() {} . The exported function can be imported by using a named import as import {sum} from './another-file' . You can use as many named exports as necessary in a single file.


1 Answers

It's instructive to look at the forthcoming Java 8 functional interfaces

The Java 8 class library has a new package, java.util.functions, which contains several new functional interfaces. Many of these can be used with the Collections API.

If you follow the patterns exhibited here, you'll have a functional interface (an interface supporting one method) and an implementation with no members. Your function object shouldn't call any methods on the method arguments that could change their state (i.e. exhibit side-effects). Unfortunately you can't enforce that - you have to rely on convention for this.

like image 135
Brian Agnew Avatar answered Oct 26 '22 06:10

Brian Agnew