Why checkStartAndEnd is not found in Android java.util.Arrays? - android

I look at Android source code
https://android.googlesource.com/platform/libcore/+/cff1616/luni/src/main/java/java/util/Arrays.java#1742
I realize Android's Arrays contains a public static method named checkStartAndEnd, which is not found in Java standard SE.
However, when I type java.util.Arrays.checkStartAndEnd in Android Studio, or look at the documentation https://developer.android.com/reference/java/util/Arrays.html, I realize checkStartAndEnd isn't valid for Android's Arrays class.
May I know why is it so? Am I looking at wrong Android source code?

You cannot see / use it because it's hidden (check the #hide tag in the Javadoc). If you compare the Android Arrays class with the Java SE one, you'll see that this checkStartAndEnd basically equals to rangeCheck, which is a private method there as well. As to why did they rename it? I have no idea, maybe some licensing issue or something else.

Related

Why are ViewPropertyAnimatorRT missing in API 29?

I want to use this class to render the animation in the word thread,
But now I can't find this class, who can tell me why this class was deleted?
question why it was removed should be answered by someone from Android team. probably they just refactored some internal animation utils due to new possibilities...
you can always copy-paste this class source and paste into your project (with different name just in case), you probably should find workaround for FallbackLUTInterpolator usage (or just remove related items, supplying different Interpolator in this place, eg. linear)
SOURCE

Why does kotlin change method invocation by variable name

If I write in Android Studio in a kotlin file getPackageManager this is automatically changed to "packageManager" in cursive, why does this happen and why should somebody think that this is straightforward to understand?
If I write in Android Studio in a kotlin file getPackageManager this is automatically changed to "packageManager" in cursive, why does this happen
getPackageManager() is a method written in Java. By convention, a method starting with get in Java is considered a field accessor. In Kotlin fields are accessed through properties. When inter-opting with Java, Kotlin automatically converts the Java way of accessing properties with the Kotlin way. This makes your code consistently "Kotliny" even if you're accessing Java classes.
Why should somebody think that this is straightforward to understand?
Because - like the syntax in the Kotlin language itself - once you know how it works, it's straightforward to understand. This goes for most things one learns. Why would someone think this is not straightforward to understand?
So, it means you could understand the cursive stuff like an alias? because normally what you write in a file is something that exists, if you write getPackageManager this exists somewhere, if you write the name of a variable this exists somewhere, but in this case packageManager doesn't really exist
Well, it does exist because the compiler makes it exist, otherwise it wouldn't compile, would it? It's just syntactic sugar. You see packageManager (so that - again - your code looks more like Kotlin). Meanwhile the compiler sees getPackageManager(). Either way it refers to the same thing.
Hope that helps!
By default all the variables are private and their getter and setter are generated by the compilers, when you pick some value it is changed to getter or when you assign value it is changed to setter call by compiler.
class Obj(var variable = "Default Value")
val obj = Obj()
obj.variable // same as obj.getVariable()
obj.variable = "Hello" // same as obj.setVariable("Hello")
Reference: https://kotlinlang.org/docs/reference/java-interop.html#getters-and-setters

What do the numbers in Android Studio debugger window mean?

What do the highlighted numbers example, 4580, 4581 etc., mean? They are not PIDs, this was crossed checked with the ps command in adb shell.
This number is the Register number of the register where the Object's reference is stored.
What is register number?
Something completely useless from an app developer point of view! I am sure you know about the Dalvik VM on which android applications run. So, the frames in a Dalvik byte code are made up of registers. And these registers store the object references. Check this link to know more. Not sure why android studio shows them in debugger. I don't see any use of it.
In short: The number may not necessarily be the register number, it could be the ID from ObjectReferenceImpl, which is an implementation of ObjectReference interface from Java Debug Interface (JDI).
In length: From analysis of Idea Community code base, ThreadDescriptorImpl.java (ThreadDescriptorImpl), was found to be the class responsible for providing the thread description to be displayed in the debug window (please refer above image presented with the question). The ID is referred as thread.uniqueID(). The thread here is of ThreadReferenceProxyImpl type which extends ObjectReferenceProxyImpl, where the uniqueID method is implemented. This method in turn returns a uniqueID from an object of ObjectReference type. Upon cursory search the ObjectReference definition with satisfying criteria was not found in Idea code base. It was later found to be hidden in the definition of JDI interface. From the JDI implementation jar found in the Idea setup, ObjectReferenceImpl was found to provide the final implementation of uniqueID method. The code snippet is listed below -
private long myID;
private static synchronized long nextID()
{
return nextID++;
}
ObjectReferenceImpl(VirtualMachine aVm, Oop oRef)
{
super(aVm);
this.saObject = oRef;
this.myID = nextID();
}
public long uniqueID()
{
return this.myID;
}
However in saying so and answering the question, words like 'probably' and 'may be' were used because, the references for ObjectReference implementations were not found immediately in the Idea Community edition source code. And, the inferences were from the jar implementations. If direct references were to be provided in the future by someone looking at this question and answer, the answer can be modified to reflect certainty.

why Google calls variables with the prefix "m"?

why Google calls variables with the prefix "m" for example:
private int mSectionResourceId;
private int mTextResourceId;
I see it in all examples. But i not understand why they do it?
And now i have some example where it practic very good. If a called variabels without prefix i need write
public SimpleSectionedRecyclerViewAdapter(Context context, int sectionResourceId, int textResourceId,
RecyclerView.Adapter baseAdapter) {
this.sectionResourceId = sectionResourceId;
this.textResourceId = textResourceId;
but if i use prefix i can write
public SimpleSectionedRecyclerViewAdapter(Context context, int sectionResourceId, int textResourceId,
RecyclerView.Adapter baseAdapter) {
mSectionResourceId = sectionResourceId;
mTextResourceId = textResourceId;
I think it more readable. Who can explain to me the pros and cons of a prefix?
The variables starting with m are telling you they are variables in the scope of your class. Member of the class.
Link to Android Code Style Guide
The m just stands for 'Member'. It is simply declared that your Variable is a Class-Member.
It is more readable Code, because you know where Class Members got declared, so you can find it pretty fast. You don't need to write this, even if you don't prefix your Variables with an m.
In your Example, this only makes it more readable when there is no prefix-m. Another developer knows that it is a instance variable (member variable) and so declared on top or bottom of the class.
It is a prefix for class member variables. It's just a naming convention.
Mostly sure, taken from Hungarian Notation where similar prefix: m_ stands for exactly the same).
Referring to pros & cons:
Pros:
it allows to type fewer chars during programming,
programmers that are used to use Hungarian Notation may found it easier to follow the code.
Cons:
as the code changes very often, it is easy to forget about changing prefixes every time, when variable changes it's purpose (especially during prototyping),
it makes the code starts to smell bad,
Generally, it is some kind of reinventing the wheel. Java has this keyword that should be more than enough for accessing proper variable. If it's not, the code requires refactoring, maybe because of naming glitches or using too wide variable scopes.
Personally, I do not recommend to use Hungarian Notation (even the part of Android Code Style). We have great IDEs that increases the readability of the code.
There is an exception. The code, where Hungarian Notation (or more general, specific code style) was already been used. It is a matter of consistency.
The m is just a member variable. A class member if you will. Useable with constructors like WebView M WebView then later on you would use something like mWebView.loadurl("example.com"); it's just a placeholder for the variable you created. You don't have to add the member class variable as an m but it's more organized if you do

Android Test - With FEST - isEquals result

I would like to know how would be the implementation to compare 2 equal results (int).
I looked for FEST documentation, but I just could find a few tutorials.
When implementing with assertThat, I cannot find the right implementation to compare same values.
FEST-Android doesn't have an api to compare primitives, but regular FEST does. You can refer to it by its fully qualified name if you want to use it.
This would look like:
org.fest.assertions.api.Assertions.assertThat(myObject.getInt()).isEqualTo(5);
Not necessarily ideal. It's too bad these aren't included in FEST-Android, as I end up either doing this or mixing and matching with JUnit assertions, which I don't love.
You can find the code here.
EDIT: You can actually just import both methods, you don't need to use the fully qualified name.
import static org.fest.assertions.api.Assertions.assertThat;
import static org.fest.assertions.api.ANDROID.assertThat;
I also not found any equals method which compare two int parameters. But I think there aren't designed Fest API to compare primitives. So, you can use simple JUnit API for compare primitives. Meanwhile I found this example:
FEST Android:
assertThat(view).isGone();
Regular JUnit:
assertEquals(View.GONE, view.getVisibility());
Please check this documentation. The ANDROID class containt many asserThan methods to compare android objects.

Categories

Resources