Skip to content

Instantly share code, notes, and snippets.

@bbarker
Last active December 12, 2021 05:21
Show Gist options
  • Save bbarker/4c8b38c9377e22b404ec025183ebc349 to your computer and use it in GitHub Desktop.
Save bbarker/4c8b38c9377e22b404ec025183ebc349 to your computer and use it in GitHub Desktop.
This example has the same result in Scala 2, though in Java there is one difference that relates to the fact that Java (unlike Scala) does not support declaration-site variance
ArrayList<JavaBean<Object>> beanList1 = new ArrayList(Arrays.asList(bean1, bean2, bean3));
public <A> void polySetAllBeansToFirst(List<JavaBean<A>> beanList) {
beanList.forEach((bean) -> bean.setTheA(beanList.get(0).getTheA()));
}
polySetAllBeansToFirst(beanList1);
// ^ We can't do this in Scala, because we can't even construct beanList1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment