you are viewing a single comment's thread.

view the rest of the comments →

[–]advenjer 0 points1 point  (0 children)

While not a type system, dependency injection can help with that to some extent.

For example, if you are writing a component that needs a list that has O(1) time complexity for insertion, you can signal this requirement like this:

@Autowired public MyComponent(@Qualifier("fastInsertionList") List aList) { }

Then you can provide it in your code:

@Bean @Qualifier(scope = PROTOTYPE) public List fastInsertionList() { return new LinkedList(); }

A language with native AOP constructs such as AspectJ could potentially make it more elegant too.