Skip to main content
Filter by
Sorted by
Tagged with
-1 votes
1 answer
77 views

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 ...
JHBonarius's user avatar
  • 11.5k
1 vote
2 answers
250 views

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 ...
JHBonarius's user avatar
  • 11.5k
0 votes
1 answer
89 views

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 ...
Raheel Khan's user avatar
  • 14.8k
3 votes
1 answer
120 views

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) ...
Roman's user avatar
  • 1,520
2 votes
2 answers
342 views

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 ...
Matteo Monti's user avatar
  • 9,120
-1 votes
1 answer
63 views

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 => &...
Charles Burns's user avatar
1 vote
0 answers
103 views

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: ...
baddie's user avatar
  • 626
0 votes
2 answers
883 views

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 ...
eng.abeer's user avatar
1 vote
1 answer
94 views

Just the code: public interface ICalculator { public double Calculate(double x) => x + 5; } public class Calculator: ICalculator { } public static class Program { static void Main() { ...
Mark Shevchenko's user avatar
1 vote
1 answer
647 views

Consider the following interface, with a default implementation of TestMethod public interface TestInterface { public int TestMethod() { return 15; } } Calling TestMethod in the ...
Tester Bill's user avatar
-2 votes
1 answer
78 views

For example: interface IDottable : IGetDottable { bool try_dot_operator(string name); // ... more methods IDottable Dottable => this; } interface IGetDottable { IDottable Dottable {...
trinalbadger587's user avatar
9 votes
2 answers
2k views

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 ...
Rüdiger Ludwig's user avatar
1 vote
1 answer
1k views

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' - ...
IUnknown's user avatar
  • 10k
10 votes
1 answer
16k views

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 ...
AndrewToasterr's user avatar
2 votes
1 answer
253 views

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 ...
Tchelyzt's user avatar
  • 181
2 votes
1 answer
129 views

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 = ...
user3680029's user avatar
2 votes
0 answers
71 views

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 ...
yeputons's user avatar
  • 9,318
2 votes
1 answer
761 views

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 ...
Anders Clausen's user avatar
0 votes
1 answer
389 views

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 ...
Rob's user avatar
  • 1,034
0 votes
1 answer
303 views

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(...
kbec's user avatar
  • 3,463
2 votes
1 answer
1k views

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 ...
Mark's user avatar
  • 20.2k
0 votes
1 answer
606 views

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"&...
Sagar Sarwe's user avatar
7 votes
2 answers
519 views

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/...
P. Sharma's user avatar
1 vote
1 answer
2k views

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: ...
Mischa's user avatar
  • 17.5k
3 votes
2 answers
939 views

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 ...
ThinkChaos's user avatar
  • 1,893
0 votes
1 answer
298 views

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"...
AV8R's user avatar
  • 63
0 votes
1 answer
299 views

Casting works just fine for instance functions. protocol Protocol1 {} extension Protocol1 { func instanceFunc() {} static func staticFunc() {} } protocol Protocol2 {} extension Protocol2 { ...
user avatar
4 votes
1 answer
754 views

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 ...
user avatar
1 vote
1 answer
230 views

.......... 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. ...
user3727894's user avatar
10 votes
3 answers
663 views

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() { ...
Kiril Kirov's user avatar
  • 38.5k
92 votes
4 answers
141k views

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 { ...
user avatar
0 votes
1 answer
827 views

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 ...
UUderzo's user avatar
1 vote
3 answers
2k views

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 ...
Aerus's user avatar
  • 4,370
51 votes
2 answers
4k views

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&...
Mihai Todor's user avatar
  • 8,384
1 vote
3 answers
1k views

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 ...
MPavlak's user avatar
  • 2,231
27 votes
3 answers
16k views

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 ...
Mark A. Donohoe's user avatar
26 votes
6 answers
17k views

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. ...
fbrereto's user avatar
  • 36.1k