question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should Java Interfaces be Matchable?

See original GitHub issue

Compiler version

3.2.0

Minimized example

It is a bit difficult to get a minimized example on this. An example of a specific commit fff0be9beb2c1edfabb9e385b72f12c21000f93f of banana-rdf, diesel branch. This was a commit to solve the answer to the problem @bishabosha came up with in issue 13416 and discussed on scala-users thread lib unification with match types. The answer worked for 2 out of 3 cases (wee below).

(btw. the pattern discussed in the thread seems so useful it seems to me, it should have a name. Perhaps it does?)

Output

Update: For a simplified version of the problem see the comment below

Having made the changes proposed by @bishabosha on that commit, two implementations worked well (Jena RDF and Tim Berners-Lee’s rdflib.js) but we had a problem with the Eclipse RDF4J implementation. My best explanation for the otherwise minor difference in code, is that Eclipse is built around interfaces whereas Jena is built on classes. And I guess Interfaces don’t implement Matchable by default.

Here is the type of error I was getting:

[error] -- [E038] Declaration Error: /Volumes/Dev/hjs/Programming/Scala3/CoSy/banana-rdf/scala3/rdf4j/src/main/scala/org/w3/banana/rdf4j/Rdf4j.scala:410:32
[error] 410 |         override protected def stringVal(uri: RDF.URI[R]): String =
[error]     |                                ^
[error]     |method stringVal has a different signature than the overridden declaration
[error]     |---------------------------------------------------------------------------
[error]     | Explanation (enabled by `-explain`)
[error]     |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]     | There must be a non-final field or method with the name stringVal and the
[error]     | same parameter list in a super class of object URI to override it.
[error]     |
[error]     |   protected override def stringVal
[error]     |   (uri: org.eclipse.rdf4j.model.IRI & (org.eclipse.rdf4j.model.Value & (
[error]     |     org.eclipse.rdf4j.model.Value
[error]     |    & Matchable)) & (org.eclipse.rdf4j.model.IRI & (org.eclipse.rdf4j.model.Value
[error]     |
[error]     |   & Matchable))): String
[error]     |
[error]     | The super classes of object URI contain the following members
[error]     | named stringVal:
[error]     |   protected def stringVal
[error]     |   (uri: org.w3.banana.RDF.URI[org.w3.banana.rdf4j.Rdf4j.R]): String
[error]      ---------------------------------------------------------------------------
[error] Explanation
[error] ===========
[error] There must be a non-final field or method with the name stringVal and the
[error] same parameter list in a super class of object URI to override it.
[error]
[error]   protected override def stringVal
[error]   (uri: org.eclipse.rdf4j.model.IRI & (org.eclipse.rdf4j.model.Value & (
[error]     org.eclipse.rdf4j.model.Value
[error]    & Matchable)) & (org.eclipse.rdf4j.model.IRI & (org.eclipse.rdf4j.model.Value
[error]
[error]   & Matchable))): String
[error]
[error] The super classes of object URI contain the following members
[error] named stringVal:
[error]   protected def stringVal
[error]   (uri: org.w3.banana.RDF.URI[org.w3.banana.rdf4j.Rdf4j.R]): String

Expectation

It’s difficult to have an expectation here. Should Java interfaces be Matchable automatically?

If not then I’ll need to find a workaround. That is not so easy because all of rdf4j is built around interfaces, and they use factories to create objects that just return the interface. So one would need to change a lot there…

Is there a java interface for Matchable that I could add to the top of the hierarchy of rdf4j Node hierarchy to check if this is the problem?

I’ll try to see if I can find a minimal example code to duplicate the problem… But if you have any thoughts on the main question that would help.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SethTisuecommented, Oct 26, 2022

We’re pursuing this on Discord, but regardless, I’m going to close this for now because

• I originally suggested opening the ticket here in the first place because of a hypothesis which has now proved incorrect • We haven’t yet been able to reproduce the problem on any computer except @bblfish’s

We can reopen the ticket (or make a new one, if it turns out the nature of the problem is entirely different than originally suspected) if or when new information comes to light.

1reaction
SethTisuecommented, Oct 25, 2022

note the -source future flag does not work with scala-cli

it does if you add -O, e.g. scala-cli compile -O -source:future . (or scala-cli compile -O -source -O future .), as per https://scala-cli.virtuslab.org/docs/commands/compile#scala-compiler-options

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interface naming in Java [closed] - Stack Overflow
Using interfaces in clients is the standard best way to program, so interfaces names should be as short and pleasant as possible. Implementing ......
Read more >
Java - Interfaces - Tutorialspoint
An interface is a reference type in Java. It is similar to class. It is a collection of abstract methods. A class implements...
Read more >
Solved MATCHABLE INTERFACE Define a generic ... - Chegg
A Matchable object can compare different types of things, such as hobbies, interests, numerical attributes, etc. Thus, the interface should be generic. For ......
Read more >
Fight ambiguity and improve your code with Java 17's sealed ...
Use sealed classes and interfaces to create hierarchies that accurately reflect your business domain and knowledge.
Read more >
Coding to an interface vs more generic interfaces
All objects implementing a particular interface must not only define methods with matching signatures, but also with matching semantics.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found