Hacker News new | ask | show | jobs
by CmonDev 4399 days ago
// protocol = interface

interface ISample { void Process(); }

ISample sample = new ConcreteSample(); // Duty #1

class GenericSampleProcessor<T> : where T : ISample // Duty #2

{ public void Process(T sample) { sample.Process(); } }

1 comments

Ah, i see, thanks.

It's the same in Java:

  ISample sample = new ConcreteSample(); // Duty #1

  class GenericSampleProcessor<T extends ISample> // Duty #2
Java got generics in 1.5, released September 2004, and bounded types like this were in that release. C# got generics in 2.0, released in November 2005, and i imagine it had them too. I assume Java lifted this idea from elsewhere. I am really quite surprised that Mr Hoare thinks this is a novel discovery in Rust.