37 questions
-1
votes
1
answer
77
views
Prevent duplicate boilerplate operator overloads [duplicate]
This is a follow up of this question, which might have been a XY problem. Anyhow, that was closed within a few minutes, before I could get any real help.
In our large code base (measurement processing ...
1
vote
2
answers
250
views
Prevent duplicate operator overloads implementations
In our large code base (measurement processing application) we've had bugs where values were mixed up because everything is a double. So we decided to try-out strongly named types for things like ...
0
votes
1
answer
89
views
Triggering an event from an interface method's default implementation causing a compile-time error
I am trying to use the default interface methods feature in .NET 9, C# 13.
Consider the following interface:
public interface ICustomNotifyPropertyChanged:
INotifyPropertyChanged
{
public void ...
3
votes
1
answer
120
views
How to override the default implementation of UnkeyedDecodingContainer protocol functions?
extension KeyedDecodingContainer {
func decode(_: Money.Type, forKey key: Key) throws -> Money {
let str = try decode(String.self, forKey: key)
return try str.toMoney(on: key)
...
2
votes
2
answers
342
views
Call a function if a Rust trait is implemented, do nothing otherwise
I am surprisingly stuck on a Rust problem that looks counterintuitively simple, and yet I cannot seem to figure it out. I am nearly starting to think it might be unsolvable, and yet I'm not sure what ...
-1
votes
1
answer
63
views
Default implementation for indexer [duplicate]
What is wrong with my code below or, alternatively, what is the point of a default indexer implementation if it isn't used by default?
public interface IFoo {
string this[string key] { get => &...
1
vote
0
answers
103
views
What does it mean to define a default interface implementation as 'virtual'?
I have an interface with a virtual method with a default implementation:
interface I
{
public virtual void M() => ...
}
I would like to override it like so and call the default implementation:
...
0
votes
2
answers
883
views
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 ...
1
vote
1
answer
94
views
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()
{
...
1
vote
1
answer
647
views
C# How to reference default interface implementation in implementer class [duplicate]
Consider the following interface, with a default implementation of TestMethod
public interface TestInterface
{
public int TestMethod()
{
return 15;
}
}
Calling TestMethod in the ...
-2
votes
1
answer
78
views
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 {...
9
votes
2
answers
2k
views
Rust calling default implementation of function in specialized version
I have a trait in Rust that offers a few default implementations for its functions.
trait MyTrait {
fn do_something(&self);
fn say_hello(&self) {
println!("Hello I am ...
1
vote
1
answer
1k
views
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' - ...
10
votes
1
answer
16k
views
C# 8.0 - Can't use default interface implementations
I recently read about C# 8.0 having interface default implementations, so i went into my project and tried it out, but i was met with an error instead. Target runtime doesn't support default interface ...
2
votes
1
answer
253
views
Why does the compiler not see the default code in a protocol?
Edit: I have restated and hopefully clarified this question over here. Now I've added the solution.
I've defined a function (see foo() in attached example) as a default function for structs adopting ...
2
votes
1
answer
129
views
Implementation of `first` in Arrow library
I don't understand the implementation of first in the library.
first seems to be defined recursively with *** -- I don't see when the recursion shall end!?
first :: a b c -> a (b,d) (c,d)
first = ...
2
votes
0
answers
71
views
What does 'impl MyTrait' do without 'for MyStruct' in Rust? [duplicate]
Traits in Rust allow default implementation for trait methods: you can write some implementation right inside trait MyTrait {...} and it will be used in impl MyTrait for MyStruct later.
However, you ...
2
votes
1
answer
761
views
Why were default methods included interfaces in Java 8 instead of adding additional interfaces to the Collection Framework?
Normally, an interface would be frozen once released into production.
Hence, if you need added functionality, your option in Java would be to extend an existing interface into a new interface, which ...
0
votes
1
answer
389
views
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 ...
0
votes
1
answer
303
views
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(...
2
votes
1
answer
1k
views
Default trait method implementation for all trait objects
I have a trait MyTrait, and I want all trait objects &dyn 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 ...
0
votes
1
answer
606
views
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:
<bean id="employee" class="com.ioc.entity.Employee">
</property>
<property name="list"&...
7
votes
2
answers
519
views
Open Closed Principle Vs Default Implementation
Java 8 introduced the concept of default implementation for interfaces? Isn't this violating Open Closed Principle, since based on the example on https://docs.oracle.com/javase/tutorial/java/IandI/...
1
vote
1
answer
2k
views
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: ...
3
votes
2
answers
939
views
Calling protocol default implementation from regular method, when protocol has associated type
I have a protocol that has a static method with a default parameter. I want to change the default value in a class that implements the protocol. Essentially doing what is easily done with classes and ...
0
votes
1
answer
298
views
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"...
0
votes
1
answer
299
views
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 {
...
4
votes
1
answer
754
views
How can you provide default implementations for UIPageViewControllerDataSource?
I assume that the answer to this question will address issues with Objective-C protocols in general, but this is the first problem of this type that I've come across.
I expect for these methods to be ...
1
vote
1
answer
230
views
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.
...
10
votes
3
answers
663
views
Is it safe to place definition of specialization of template member function (withOUT default body) in source file?
Here's what I mean:
// test.h
class cls
{
public:
template< typename T >
void f( T t );
};
-
// test.cpp
template<>
void cls::f( const char* )
{
}
-
// main.cpp
int main()
{
...
92
votes
4
answers
141k
views
Can an interface method have a body?
I know that an interface is like a 100% pure abstract class. So, it can't have method implementation in it. But, I saw a strange code. Can anyone explain it?
Code Snippet:
interface Whoa {
...
0
votes
1
answer
827
views
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 ...
1
vote
3
answers
2k
views
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 ...
51
votes
2
answers
4k
views
What does an ampersand after this assignment operator mean?
I was reading through this nice answer regarding the "Rule-of-five" and I've noticed something that I don't recall seeing before:
class C {
...
C& operator=(const C&) & = default;
C&...
1
vote
3
answers
1k
views
Generic class to create concrete class automatically
Is there a way to take an interface, say:
/// <summary>
/// Interface containing operators which operate on T
/// </summary>
public interface IScalarOperators<T>
{
// Adds two T ...
27
votes
3
answers
16k
views
Can you extend the default JsonConverter used in JSON.NET for collections?
I'm trying to write a custom JsonConverter for cases where a person subclasses a list or collection, but then adds extra properties to the subclass (see here). The current implementation of JSON.NET ...
26
votes
6
answers
17k
views
How do I provide a default implementation for an Objective-C protocol?
I'd like to specify an Objective-C protocol with an optional routine. When the routine is not implemented by a class conforming to the protocol I'd like to use a default implementation in its place. ...