Questions tagged [default-implementation]
30 questions
1
vote
1 answer
Can the interface method with default implementation be implemented implicitly in a class?
Just the code:
public interface ICalculator
{
public double Calculate(double x) => x + 5;
}
public class Calculator: ICalculator
{
}
public static class Program
{
static void Main()
{
ICalculator calculator = new Calculator();
…

Mark Shevchenko
- 7,937
- 1
- 25
- 29
1
vote
1 answer
C# How to reference default interface implementation in implementer class
Consider the following interface, with a default implementation of TestMethod
public interface TestInterface
{
public int TestMethod()
{
return 15;
}
}
Calling TestMethod in the following class will cause a…

Tester Bill
- 85
- 5
1
vote
1 answer
helper function for default interface method
I need to incorporate some helper methods to assist the default method of interface on Java 8 - for better code organization.
So the only available option seems to be to qualify them with 'static' - and thus leave them exposed to outside.
Is there…

IUnknown
- 9,301
- 15
- 50
- 76
1
vote
1 answer
Default trait method implementation for all trait objects
I have a trait MyTrait, and I want all trait objects &MyTrait to be comparable to each other and to nothing else. I have that now based on How to test for equality between trait objects?.
The problem is that I need to use MyTraitComparable…

Mark
- 18,730
- 7
- 107
- 130
1
vote
1 answer
Override the setter of a protocol-defined variable and use the getter from the protocol's default implementation
I have a protocol with a single variable
protocol Localizable {
var localizationKey: String { get set }
}
for which I implement a default getter:
extension Localizable {
var localizationKey: String {
get {
assert(true,…

Mischa
- 15,816
- 8
- 59
- 117
1
vote
1 answer
What are the differences between an aggregate operation and a method?
..........
well, let me tell you i made some mistakes: the foreach() i was refering to is not an aggregate operation but a method from Iteable. I've changed the title of my question and its content.
My interest is to know if an aggregate operation…

user3727894
- 39
- 5
1
vote
2 answers
Code generation for default interface methods (in IDEA)
Before JDK 8 I would write: A implements B and hit alt+enter to automatically generate the method headers for the methods in B so I only have to fill in the method bodies.
However in JDK 8 it is possible that B provides a default implementation and…

Aerus
- 4,332
- 5
- 43
- 62
0
votes
2 answers
android - kotlin differences between Normal class and data Class of methods default implementations
I read about differences between class and dataclass in kotlin from this
https://medium.com/@dubemezeagwu/difference-between-normal-classes-data-classes-in-kotlin-a01f636e8900
i need someone explain the second point by example, when i tried it as i…

eng.abeer
- 13
- 2
0
votes
1 answer
Trouble with Swift Protocols, associatedtypes, Self and default implementations
I am trying to get some functionality through default implementations that I can't nail. Consider the following code, which is a simplification of what I'm trying to do, but captures the problem as simply as possible.
//protocol definition
protocol…

Rob
- 1,025
- 2
- 10
- 27
0
votes
1 answer
Can compiler do a default implementation's inlining of the trait's method?
I understand that the trait's method doesn't have a body, so there is nothing to inline. But is there any sense to mark its default implementation like this?
trait Magnitude {
fn square_magnitude( &self ) -> f64;
#[inline]
fn magnitude(…

kbec
- 3,415
- 3
- 27
- 42
0
votes
1 answer
Override default implementation of list or other collections in spring xml configuration file
I observed that the default implementation of list in spring xml is ArrayList.
I tried:
-
…

Sagar Sarwe
- 3
- 2
0
votes
1 answer
Is swift extension default implementation solved on compile or runtime?
I'm wondering is there a way to work with protocol default implementations in polymorphic style.
Example
protocol RockInterface {
}
extension RockInterface {
func foo() {
print("You Rock")
}
}
extension RockInterface where Self:…

AV8R
- 63
- 1
- 7
0
votes
1 answer
How do you disambiguate between static methods from implemented protocols?
Casting works just fine for instance functions.
protocol Protocol1 {}
extension Protocol1 {
func instanceFunc() {}
static func staticFunc() {}
}
protocol Protocol2 {}
extension Protocol2 {
func instanceFunc() {}
static func…
user652038
0
votes
1 answer
Using different DocumentBuilder implementations on the same Java VM
I know that this question has been already asked, but in a different flavour so i ask again from my POV.
In our application server several EJB reside (so, AFAIK, several threads, one for each EJB call). Some EJB, for proper functioning, need that…

UUderzo
- 1
- 2
-2
votes
1 answer
C# how to add a default implementation to an interface which is overriding another interface
For example:
interface IDottable : IGetDottable
{
bool try_dot_operator(string name);
// ... more methods
IDottable Dottable => this;
}
interface IGetDottable
{
IDottable Dottable {get;}
}
It gives me:
"'IDottable.Dottable' hides…

trinalbadger587
- 1,905
- 1
- 18
- 36