✅ where constraint on interface method
Is it even possible? Like
public void RefuelCar<c>(c Car) where c : IUseGas.Refuel
Here the generic type is constrainted to where it implements an interface's method, whereas the name of the interface is IUseGas
16 Replies
The name of the method is
Refuel()
ofcThat doesn't make sense
And doesn't work, of course
Classes have to implement all methods of an interface
That's what I thought. I asked because I just came back from my endterm exam where they demanded that we used it like that.
It makes no sense to check if a class implements one particular method of it
It has to
Angius
REPL Result: Failure
Exception: CompilationErrorException
Compile: 233.972ms | Execution: 0.000ms | React with ❌ to remove this embed.
It won't even compile
That's what I thought, too. That's why I didn't do it on the endterm, took my 1.3 points out of 2, so I missed 0.7 because of that. Seems like some teacher made the exam without either checking it himself or let another check. Too condfident in their code and not doing their job right.
Yeah
Whoever required you to do this way was high on fentanyl
Unless, idk, it wasn't actually C#? Lowercase types and uppercase method params, assuming that's how it looked on the exam, are not a C# naming convention
Yeah I was also confused because of how
c
wasn't uppercase.thing is it not also java
Nvm I read the instructions wrong
either its some wacky psuedocode
How do I close this thread?
you cant
$close
If you have no further questions, please use /close to mark the forum thread as answered