go like functionality in java