I have created a number of different auction implementations in Scala using type classes and ad-hoc polymorphism.
An example of a Scala implementation can be found here.
In Scala one creates an instance of this auction as follows...
val google: GoogleStock = GoogleStock(tick=1)
val pricingRule = new MidPointPricingPolicy[GoogleStock]
val withDiscriminatoryPricing = OpenBidDoubleAuction.withDiscriminatoryPricing(pricingRule)
I would like users to be able to access the auction implementations from Java 8.
But I can not seem to figure out how to create an instance of an auction in Java. Taking this approach:
MidPointPricingPolicy<GoogleStock> midPointPricing = new MidPointPricingPolicy<GoogleStock>();
OpenBidDoubleAuction.DiscriminatoryPricingImpl<GoogleStock> auction = OpenBidDoubleAuction$.MODULE$.withDiscriminatoryPricing(midPointPricing);
works, but none of the type class contract methods are available. Specifically:
OpenBidDoubleAuction.DiscriminatoryPricingImpl<GoogleStock> auction2 = auction.insert(order3);
...yields the following compile error.
Error:(90, 82) java: cannot find symbol
symbol: method insert(org.economicsl.auctions.singleunit.orders.LimitAskOrder<org.economicsl.auctions.GoogleStock>)
location: variable auction of type org.economicsl.auctions.singleunit.twosided.SealedBidDoubleAuction.UniformPricingImpl<org.economicsl.auctions.GoogleStock>
It seems that the Scala compiler generated contract methods for the type class are not available when the Java code is being compiled. In my build.sbt file I have set compileOrder := CompileOrder.ScalaThenJava in order to make sure that these Scala gets compiled first so that these methods would be available.
Based on a suggestion from @GhostCat I used javap to find out that the Scala compiler generates the following .class file...
OpenBidDoubleAuction$DiscriminatoryPricingImpl$$anon$1.class
which contains the byte code definitions of the relevant methods.
So I guess I need to know how can I access things defined in this byte code file from Java? Is it even possible?