Disallow usage of the same ID

36 views Asked by At

We are using some binary serializer and it requires us to register a serializer with an ID.

So we have a huge file which is something like this

...
registerSerializer(classOf[SomeClass1], SomeClass1Serializer, id = 3456)
registerSerializer(classOf[SomeClass2], SomeClass2Serializer, id = 3457)
registerSerializer(classOf[SomeClass3], SomeClass3Serializer, id = 3458)
...

The bigger the file, the more merge conflicts, the higher the chance (and it has happened already) that the same ID might be used more than once (which is bad).

Can we ask Scala compiler to help us here? What would be the approach were it will be a compilation error if the same id is reused? Any approach that doesn't use macros?

0

There are 0 answers