Java
public class Sample {
public static void func(Action<String> a) {
a.apply('Hello');
}
public static void main(String[] args) {
Sample.func(s -> System.out.println(s));
// 複数行の場合
Sample.func(s -> {
System.out.println(s)
System.out.println(s)
});
}
}
JavaScript
const func = (callback) => {
callback('Hello');
};
func((s) => console.log(s));
// 複数行の場合
func((s) => {
console.log(s)
console.log(s)
});
Ruby
def func
yield 'Hello'
end
func { |s| p s }
# 複数業行の場合
func do |s|
console.log(s)
console.log(s)
end
# {}でも動作するがdo~endがベター