I have a class that creates a new File object: Now I want to mock out the dependency to File. So I created an interface IFile: For the actual code I created a FileWrapper class that implements this interface and calls java.io.File: My initial idea was to use IFile in the constructor of MyClass (and create a m…
Tag: java
I want to change activity and reset timer after it finishes. Android Studio
So basically I made one minute countdown in Android Studio using java. As soon as timer riches “0”, I want to change activities and reset timer. so that when I visit this activity again, timer would work. Here’s my java code: And here’s my xml code: Answer You do the task by adding the…
Are all exceptions throw from Jdbi of type JdbiException?
It states here: https://jdbi.org/apidocs/org/jdbi/v3/core/JdbiException.html that JdbiException is the Base unchecked exception for exceptions thrown from jdbi. However, if I’m calling the withHandle method with various different callbacks: the docs state that it throws X extends Exception (rather than …
Different number of bytes when storing images to Android Q vs previous versions
we have a situation that we don’t entirely understand. In our app, the user selects images, which are saved to disc and mapped to their pictures folder. Then when the user is ready to upload the selected images, we use ByteArrayOutputStream to turn them each into a byte array, which is then turned into …
Connecting 3 tables with hibernate / spring-boot
I have problem understanding how to connect 3 tables with spring-boot / hibernate. Tables are: Users, Technologies, Categories Every user has all of the 10 categories but inside this categories they can save one or more technologies. Each technology can be listed in several different categories. I have a code…
Spring is trying to subclass a record component when aop is present
I have a spring boot application in which I make use of aspects. Recently, I tried converting my @ConfigurationProperties classes to java records, but it fails with “Cannot subclass final class {..}Properties”. It seems spring is trying to make cglib proxies for my records, which obviously fail. I…
Why is my StringBuffer variable not synchronized. Where as StringBuilder variable behaves as synchronized
I am trying to understand the difference between StringBuilder and StringBuffer. The goal of the below program is that 2 threads (Jack and Jill) compete to mutate a StringBuffer and StringBuilder values. If the original value is already modified then the thread will not modify that variable. Why is my StringB…
Why enum constructor “this” and “Enum.this” is different
I have a local enum cache, need in enum constructor return enum instance. but when return ‘this’ , it’s fail, return ‘Enum.this’ , it’s ok. the exception looks like a inner class. because this instance is not finish ? this is my code and exception Answer Here: Notice that t…
PSQLException: ERROR: operator does not exist: bigint = character varying
I am trying to do a LEFT JOIN FETCH to load a lazy loaded some data, but I am getting the following error. I have searched everywhere online to see what I am doing incorrectly, but I don’t see what I am doing differently (other than my id not being a primitive type). Here is what I have Key Repo
How to convert from a double without a fractional part to a hexaicosadecimal string (base-26)?
I am wondering how do you convert from a double without a fractional part to a hexaicosadecimal string? What are some methods for converting and are there short cuts? Answer As far as I understood it is a base 26 conversion to letters only, with a prefix “c”. Not sure on the sign for a negative- n…