How to reference Enum inside a Java class from Clojure [duplicate] - enums

This question already has an answer here:
clojure access enum defined inside a java class
(1 answer)
Closed 3 years ago.
How do I reference Enum constant which is enclosed inside a Java class from Clojure? I'm trying to use the field P2PKH from org.bitcoinj.script.Script.ScriptType. See API of bitcoinj.
In a Java interop guide they say:
You can refer to those enumerations in Clojure like this:
DaysOfWeek/TUESDAY
But that doesn't work when the Enum is enclosed in a class. What would be the correct syntax?

You need to use syntax for accessing static inner classes:
OuterClass$InnerClass/staticField
so it should be:
org.bitcoinj.script.Script$ScriptType/P2PKH.

Related

What does this Spring Component and Kotlin Class consist of? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have this class here:
#Component
class UpdateRule(
private val rulesRepo: UpdateRuleRepo
) : UpdateRuleStoreGateway, UpdateRuleLoadGateway {
override fun store(rule: UpdatRule) {
//some code
}
override fun loadAll(): List<UpdateRule> {
//some code
}
Since I'm new to Spring and Kotlin, I'm not familiar with this syntax. What does the val inside the brackets mean (private val rulesRepo: UpdateRuleRepo) and what do the interfaces after the colon do (: UpdateRuleStoreGateway, UpdateRuleLoadGateway)? Is this Kotlin specific or Spring specific syntax and where can I read more about it?
This is Kotlin syntax, not Spring-specific.
What does the val inside the brackets mean (private val rulesRepo: UpdateRuleRepo)
The part between the parentheses () is the list of arguments for the primary constructor of the class. When a constructor argument is marked val or var, it also declares a property of the same name on the class.
In this case, it means rulesRepo is a constructor argument of the class UpdateRule, but also a property of that class. Since it's a val, it means the property is read-only (it only has a getter).
You can read more about this in the docs about constructors.
what do the interfaces after the colon do (: UpdateRuleStoreGateway, UpdateRuleLoadGateway)?
The types listed after the : in a class declaration are the parent classes (or interfaces) extended (or implemented) by that class. In this case it means UpdateRule implements both interfaces UpdateRuleStoreGateway and UpdateRuleLoadGateway.
This is described in the docs about implementing interfaces.
Val is var but final to put it simply. Final means it cannot be reassigned to another object/primitive data. But do keep it mind that it doesn't mean internal data is immutable. It's not like Python tuple! Individual element/member variables can be modified, but the whole thing cannot be reassigned(think of variable as a pointer, and it's referencing to the same object, although the internal details of the object may change over time)
Kotlin var is different from Java var by the way.
More on that here: https://www.baeldung.com/kotlin/java-kotlin-var-difference
I personally find kotlin var similar to TypeScript let.

Spring AOP pointcut expression matching caller's context [duplicate]

This question already has an answer here:
Intercept a method only if that method is called from a certain class?
(1 answer)
Closed 1 year ago.
I am using Spring AOP. I want my target method be matched only when invoked from a certain package. For example, let's assume my target method is com.domain.target.MyService.run(), and that it can be accessed from anywhere in my project. However, I want the pointcut to trigger only when the method is invoked from within a certain package, say com.domain.caller.*.
Is this something doable?
Yes, it's able to advice with package.
We could also match any type within the package or a sub-package.
#Pointcut("within(com.domain.caller)")
#Pointcut("within(com.domain.caller.*)")
You can find more detail:
https://www.baeldung.com/spring-aop-pointcut-tutorial

Spring Boot Kotlin entity property val vs var [duplicate]

This question already has answers here:
What is the difference between var and val in Kotlin?
(41 answers)
Closed 1 year ago.
I am learning Spring Boot with kotlin and I am so confused with the usage of var or val for entity property. In some tutorial they use val and the other use var. So I don't know which is the right one to declare property for entity. At least enlightenment me about this. Please & Thanks!!
val and var both are used to declare variables but the main difference between them could be defined as;
val: is used when you declare a variable with a value which you don't want to change or update, it is kind of a constant variable which can only be initialized once. And when you try to change its value, it will show an error like Val can not be reassigned. it is known as immutable variable in kotlin.
On the other hand,
var: is used when you intend to declare a general variable whose value could be changed or updated anywhere in the class. It could be initialized or reassigned multiple times and it is known as mutable variable in kotlin.
I hope this will help you. There is a good definition with example.

What is the top level interface in go? [duplicate]

This question already has answers here:
What's the meaning of interface{}?
(8 answers)
Closed 7 years ago.
Or what is the interface that all types implement?
I'm looking for something like the Object class in Java.
Is it possible for me to make my own kind of "Root" interface?
Any type that implements all the methods listed in the interface implements the interface.
The empty interface, interface{}, lists no methods. Therefore, all types implement it.
There is nothing "top level" about it however. Interfaces (although they can embed) do not have a hierarchical structure. The empty interface is simply a normal interface with no requirements.

Use of enums in Java API

Could you point me out to a class, from official Java API that has a good use of enums ?
I could not find any specific class.
Does the Java API incorporates enums in their classes at all?
There are 328 enum classes defined in the JRE 7. I suggest you read the Enum Types tutorial
A simple one I have used is java.nio.AccessMode.
An enum worth understanding is Thread.State
A more interesting one is java.util.concurrent.TimeUnit
An example of a class which IMHO would be an enum but predates them is ByteOrder See Joachim's comment above.
There are few in Collection API which directly use Enum : EnumSet, EnumMap

Resources